ITeye博客

spring中配置使用事务

pignut_wang · 2007-02-18 14:00 · struts+spring · Spring · AOP · Bean · Markdown

使用如下配置方式实现:

无论在方法中发生任何异常,只要方法中抛出一个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"/>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。