spring中配置使用事务

使用如下配置方式实现:

无论在方法中发生任何异常,只要方法中抛出一个Exception,包括是自己设置抛出的异常,事务都进行回滚

对比1.1与2.0中事务的配置方法

配置文件如下 1.1

  1. <bean id="baseTxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"           abstract="true">    
  2.         <property name="transactionManager" ref="transactionManager"/>    
  3.         <property name="proxyTargetClass" value="true"/>  
  4.          <property name="transactionAttributes">  
  5.              <props>    
  6.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly </prop>    
  7.                 <prop key="find*">PROPAGATION_REQUIRED,readOnly </prop>    
  8.                 <prop key="save*">PROPAGATION_REQUIRED,-Exception </prop>    
  9.                 <prop key="remove*">PROPAGATION_REQUIRED ,-Exception </prop>  
  10.             props>    
  11.         property>  
  12.          <property name="preInterceptors">    
  13.             <list>  
  14.                  <ref bean="methodSecurityInterceptor"/>  
  15.              list>    
  16.         property>  
  17.   bean>  
  18.   <bean id="bookManager" parent="baseTxService">  
  19.          <property name="target">    
  20.             <bean class="org.springside.bookstore.admin.manager.BookManager"/>  
  21.            property>  
  22.   bean>  

 

spring 2.0 中事务配置方法

  1. <aop:config proxy-target-class="true">  
  2.      <aop:advisor pointcut="execution(* *..*Manager.*(..))" advice-ref="txAdvice"/>  
  3.      <aop:advisor pointcut="execution(* *..*Manager.save(..))" advice-ref="fooAdvice"/> aop:config>  
  4. <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  5.      <tx:attributes>  
  6.          <tx:method name="save*"/>  
  7.          <tx:method name="remove*"/>  
  8.          <tx:method name="*" read-only="true"/>  
  9.     tx:attributes>  
  10.  tx:advice>  
  11.   <bean id="bookManager" class="org.springside.bookstore.commons.service.BookManager"/>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值