事务控制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="transfer"/> <tx:method name="*"/> </tx:attributes> </tx:advice>
<aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* service.impl.*.*(..))"/> </aop:config>
|
Annotation配置
1 2 3 4 5 6 7
| <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
|
@Transactional 可以在类上也可以在方法上, 就近原则