事先准备:
配置数据源对象
用<bean>实例化各个业务对象。
1.配置事务管理器。
<bean id="transactionManager" class="org.springframework.jdbc.datasourceManager"> <property name="datasource" ref="datasource"></property> </bean>
2.配置事务属性
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="方法名" propagation="REQUIRES_NEW"/> <!--新开事务--> <tx:method name="*"/> <!--使用原有事务--> </tx:attributes> </tx:advice>
3.配置事务切入点,注入事务属性
<aop:config> <aop:pointcut expression="execution(.......)" id="txPointCut"/> <aop:advisor advice-ref="txtAdvice" pointcut-ref="txtPointCut"/> </aop:config>