spring+ibatis事务配置

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xsi:schemaLocation="   
          http://www.springframework.org/schema/beans    
          http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
          http://www.springframework.org/schema/aop    
          http://www.springframework.org/schema/aop/spring-aop-2.0.xsd   
          http://www.springframework.org/schema/tx    
          http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "> 
          
          
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > 
<property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
<property name="url" value="jdbc:mysql://10.11.0.145:3306/carrefour?characterEncoding=gb2312" /> 
<property name="username" value="dev01" /> 
<property name="password" value="123456" /> 
</bean> 
<bean id="sqlClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> 
<property name="dataSource"> 
<ref local="dataSource" /> 
</property> 
<property name="configLocation"> 
<value>classpath:sqlmaps.xml</value> 
</property> 
</bean> 
<!--配置事务管理器--> 
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
        <property name="dataSource" ref="dataSource"></property> 
</bean> 
<!--配置哪些方法,什么情况下需要回滚--> 
<tx:advice id="serviceAdvice" transaction-manager="transactionManager">  
    <tx:attributes>   
        <!--当代理的service层中的方法抛出异常的时候才回滚,必须加rollback-for参数--> 
        <tx:method name="insert*" propagation="REQUIRED" rollback-for="Throwable"/> 
        <tx:method name="del*" propagation="REQUIRED" rollback-for="Throwable"/>  
        <tx:method name="update*" propagation="REQUIRED" rollback-for="Throwable"/>  
        <!--除了上面标识的方法,其他方法全是只读方法--> 
        <tx:method name="*" read-only="true"/>  
    </tx:attributes>  
</tx:advice>  
<!-- 配置哪些类的方法需要进行事务管理 -->  
<aop:config proxy-target-class="true">  
<aop:pointcut id="servicePointcut" expression="execution(* com.crm.service.*.*(..))"/>  
<aop:advisor pointcut-ref="servicePointcut" advice-ref="serviceAdvice"/>  
</aop:config> 
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页