- 一 配置平台事务管理器
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource2" /> </bean>
- 配置事务的增强
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 事务管理的规则 --> <!-- <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true"/> --> <tx:method name="*" propagation="REQUIRED" read-only="false" /> </tx:attributes> </tx:advice>
- Aop 切面 切入点的配置
<!-- aop的配置 --> <aop:config> <aop:pointcut expression="execution(* com.cws.txdemo1.AccountServiceImpl.*(..))" id="pointcut1" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1" /> </aop:config>
调用
/** * * @author Aurora * 实现类实现接口,在xml中注入实现类 * 在调用实现类中方法时 * 新建接口,将实现类注入接口 * 通过接口调用方法实现实现类 * * 也就是在xml中配置的是实现类 * 在调用方法时新建的是接口 * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:txapplicationContext.xml") public class Txdemo1 { //注入AccountService @Resource(name="accountService") private AccountService acc; @Test public void test() { acc.tranAccount("张三", "陈文硕", 1000d); } }
spring 中基本事务的xml配置
猜你喜欢
转载自blog.csdn.net/qq_38474916/article/details/82152621
今日推荐
周排行