mybatis配置

4 篇文章 0 订阅
2 篇文章 0 订阅

mybatis_resource.xml

<!--  

初始化连接
dataSource.initialSize=10
最小空闲连接
dataSource.minIdle=5
最大空闲连接 
dataSource.maxIdle=20
最大连接数量
dataSource.maxActive=50
超时等待时间以毫秒为单位 6000毫秒/1000等于6秒
maxWait=6000
是否在自动回收超时连接的时候打印连接的超时错误
dataSource.logAbandoned=true
是否自动回收超时连接
dataSource.removeAbandoned=true
超时时间(以秒数为单位)
dataSource.removeAbandonedTimeout=180
-->  
<!-- 数据库连接池 -->
<bean id="dataSourceMyBatis" 
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" 
p:driverClassName="${jdbc.driverClassName}" 
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
p:initialSize="${c3p0.initialPoolSize}" 
p:minIdle="${c3p0.minPoolSize}"
p:maxIdle="50" 
p:maxActive="${c3p0.maxPoolSize}" 
p:maxWait="6000"
p:logAbandoned="true"
p:removeAbandoned="true"
p:removeAbandonedTimeout="180" /> 
  

<!-- Mybatis's sqlSessionFactory config -->
<bean id="sqlSessionFactoryMyBatis" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSourceMyBatis" 
p:configLocation="classpath:mybatis/mybatis-config.xml"
p:mapperLocations="classpath:mybatis/mapper/**/*.xml"/>

<bean name="transactionManagerMyBatis"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceMyBatis"></property>
</bean>


<!-- 启用注解式事务 -->
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManagerMyBatis" /> 


<!-- 启用声明式事务 -->
<tx:advice id="txAdviceMyBatis" transaction-manager="transactionManagerMyBatis">
<tx:attributes>
<!-- 新增一类的关键字 -->
<tx:method name="create*" propagation="REQUIRED"  rollback-for="Throwable" />
<tx:method name="add*"    propagation="REQUIRED"  rollback-for="Throwable" />
<tx:method name="save*"   propagation="REQUIRED"  rollback-for="Throwable" />
<!-- 更新一类的关键字 -->
<tx:method name="modify*" propagation="REQUIRED"  rollback-for="Throwable" />
<tx:method name="update*" propagation="REQUIRED"  rollback-for="Throwable" />
<!-- 删除一类的关键字 -->
<tx:method name="delete*" propagation="REQUIRED"  rollback-for="Throwable" />
<tx:method name="remove*" propagation="REQUIRED"  rollback-for="Throwable" />
<!-- 其他方法只读 -->
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 给所有的service类添加事务拦截 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* a.b.c..service.*.*(..))" />
<aop:advisor advice-ref="txAdviceMyBatis" pointcut-ref="serviceOperation" />
</aop:config>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值