ssm整合配置文件编写


表头
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">


具体实现


    <!--1.加载db.properties-->
    <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
    <!--2.数据源-->
    <!--  mybatis层配置-->
    <!--配置德鲁伊数据源-->
    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <!--配置用户名密码和地址,驱动可以不配置,在url配置是自动寻找并加载-->
        <property name="username" value="${jdbc_username}"></property>
        <property name="password" value="${jdbc_password}"></property>
        <property name="url" value="${jdbc_url}"></property>
        <!--  数据源初始化时开启线程池连接数为5-->
        <property name="initialSize" value="15"></property>
        <!--最大连接数-->
        <property name="maxActive" value="30"></property>
        <!--最小连接数-->
        <property name="minIdle" value="5"></property>
    </bean>
    <!-- 3.sqlsessionfactory 配置该实现类不用new,并且易于修改-->
    <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--链接数据源-->
        <property name="dataSource" ref="druidDataSource"></property>
        <!--   导入mapper.xml即导入映射文件,相当于mybasic-config.xml文件中的mapper映射注册-->
        <property name="mapperLocations" value="mapper/*.xml"></property>
        <!--  给该包下面的所有类取别名 默认为类名-->
        <!--  给每一个需要的的实体类手动取别名-->
        <property name="typeAliasesPackage" value="com.vp.pojo"></property>
<!-- 4.4配置PageHelper的参数实现分页 -->//需要导包
 <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>
                            helperDialect=mysql
                            reasonable=true
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <!-- 4.将映射文件与接口建立关联 形成链式编程-->
    <!--使用mapper包下的该工具类-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--  将dao层对应的接口导入-->
        <property name="basePackage" value="com.vp.dao"></property>
        <!--使用工厂将接口与映射文件相关联-->
        <property name="sqlSessionFactoryBeanName" value="sqlsessionFactory"></property>
    </bean>

    <!--spring配置-->
    <!-- 1。开启扫描器-->
    <context:component-scan base-package="com.vp"></context:component-scan>
    <!--2.开启声明式事务的注解-->
    <context:annotation-config></context:annotation-config>

    <!--2.开启声明式事务的注解-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--     连接数据源-->
        <property name="dataSource" ref="druidDataSource"></property>
    </bean>
    <!--    验证spring事务-->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
    <!--如果没有这一行,那么会使用jdk动态代理进行声明事务,使用该代码会使用cg-lib进行操作-->
    <aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值