事务管理与容错机制实现
1. AspectJ织入式事务管理
在某些情况下,基于代理的解决方案可能不够用,Spring扩展了注解驱动的事务管理支持,引入了基于AspectJ的织入方式。要启用基于AspectJ织入的事务管理,需要为 <tx:annotation-driven> 元素指定 mode 属性,示例如下:
<tx:annotation-driven mode="aspectj"/>
和基于代理的事务管理类似,如果有一个名为 transactionManager 的bean,切面会使用它来驱动事务,也可以指定 transactionManager 属性。要使该方案生效,必须使用第8章中描述的某种形式的AspectJ织入器(编译时或加载时织入器,包括Spring驱动的加载时织入器)。
执行带有AspectJ织入器的主驱动程序时,会得到如下输出:
EntityManager:
[AbstractEntityManagerImpl.getTransaction() on 4213679]
Starting transaction [Read only: true, New transaction: true]
Entering [ProductServiceImpl.findProduct(..)]
Entering [JpaGe
超级会员免费看
订阅专栏 解锁全文
1185

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



