spring配置事務管理器,事務配置
阿新 • • 發佈:2019-01-27
<!-- 配置事務管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" /> <!-- 通過AOP配置提供事務增強,讓service包下所有Bean的所有方法擁有事務 --> <aop:config proxy-target-class="true"> <aop:pointcut id="serviceMethod" expression="(execution(* chapter2.service..*(..))) and (@annotation(org.springframework.transaction.annotation.Transactional))" /> <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" /> </tx:attributes> </tx:advice>