Spring AOP 事务不是工作在以下拦截器?
<bean id="testAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="urlInterceptorInsert" /> <idref bean="urlInterceptorCommit" /> <idref bean="urlInterceptorRelease" /> <idref bean="matchGenericTxInterceptor" /> </list> </property> <property name="beanNames"> <list> <idref local="urlBo" /> </list> </property> </bean>
matchGenericTxInterceptor”事务拦截器,假设来拦截器 urlInterceptorInsert,urlInterceptorCommit,urlInterceptorRelease, 但不能如预期一样工作?
解决
3个拦截器在事务管理器拦截器(matchGenericTxInterceptor)之前执行。
为了解决这个问题,必须改变拦截器 XML文件的顺序,如下面的(把 matchGenericTxInterceptor 放在顶部)。
<bean id="testAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="matchGenericTxInterceptor" /> <idref bean="urlInterceptorInsert" /> <idref bean="urlInterceptorCommit" /> <idref bean="urlInterceptorRelease" /> </list> </property> <property name="beanNames"> <list> <idref local="urlBo" /> </list> </property> </bean>
注 Spring AOP的拦截器的顺序对功能有影响。
易百教程移动端:请扫描本页面底部(右侧)二维码并关注微信公众号,回复:"教程" 选择相关教程阅读或直接访问:http://m.yiibai.com 。
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加3个群。
- Java技术群: 227270512 (人数:2000,等级:LV5,免费:否)
- MySQL/SQL群: 418407075 (人数:2000,等级:LV5,免费:否)
- 大数据开发群: 655154550 (人数:2000,等级:LV5,免费:否)
- Python技术群: 287904175 (人数:2000,等级:LV5,免费:否)
- 人工智能深度学习: 456236082 (人数:2000,等级:LV5,免费:否)
- 测试工程师(新群): 415553199 (人数:1000,等级:LV1,免费:是)
- 前端技术群(新群): 410430016 (人数:1000,等级:LV1,免费:是)
- C/C++技术(新群): 629264796 (人数:1000,等级:LV1,免费:是)
- Node.js技术(新群): 621549808 (人数:1000,等级:LV1,免费:是)
- PostgreSQL数据库(新群): 539504187 (人数:1000,等级:LV1,免费:否)
- Linux技术: 479429477 (人数:2000,等级:LV5,免费:否)
- PHP开发者: 460153241 (人数:2000,等级:LV5,免费:是)
- Oracle数据库: 175248146 (人数:2000,等级:LV5,免费:是)
- C#/ASP.Net开发者: 579821706 (人数:2000,等级:LV5,免费:是)
- 数据分析师: 397883996 (人数:1000,等级:LV1,免费:是)R语言,Matlab语言等技术