<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <constructor-arg ref="transactionManager" /> </bean> <!-- 事务拦截器 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- methods starting tx, just as 'save', 'update' or 'remove' use the default transaction settings --> <tx:method name="save*" /> <tx:method name="update*" /> <tx:method name="remove*" /> <tx:method name="delete*" /> <!-- other methods are set to read only --> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 事务拦截包配置 myproject..*Service.*(..),对package gov.UserService 的方法都拦截 --> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* gov..*Service.*(..))" advice-ref="txAdvice" /> </aop:config> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* gov..*Manager.*(..))" advice-ref="txAdvice" /> </aop:config>
本文介绍如何使用Spring框架进行事务管理配置,包括DataSourceTransactionManager、TransactionTemplate的定义及使用,通过AOP实现对指定包下的Service和Manager层方法的事务拦截,并设置不同方法类型的默认事务属性。
501

被折叠的 条评论
为什么被折叠?



