spring 声明式事务、异步调用、AOP灯增强类功能 失效问题
2015-11-10 15:41
417 查看
今天测试的时候发现一个问题,就是我们现有项目中的事务配置是无效的,原因如下:
服务器启动时配置文件的加载顺序是 web.xml --->applicationContx.xml(spring总配置文件)-->applicationContext-mvc.xml,
由于applicationContx.xml中Controller会先进行扫描装配,但是此时service还没有进行事务增强处理,得到的将是原样的
service(没有进行事务加强,因而没有事务处理能力),因此在applicationContx.xml中一定要先扫描 service,
<context:component-scan base-package="com.XX*" scoped-proxy="targetClass">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
然后在applicationContext-mvc.xml中再扫描 Controller
<context:component-scan base-package="com.xx" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
如未按照这样的顺序扫描,就可能引起事务失效。
2017-10-06 追加:
其他增强类功能如 异步调用、AOP功能失效,大多是配置错误导致,Controller层装配了未增强的 raw Bean。
服务器启动时配置文件的加载顺序是 web.xml --->applicationContx.xml(spring总配置文件)-->applicationContext-mvc.xml,
由于applicationContx.xml中Controller会先进行扫描装配,但是此时service还没有进行事务增强处理,得到的将是原样的
service(没有进行事务加强,因而没有事务处理能力),因此在applicationContx.xml中一定要先扫描 service,
<context:component-scan base-package="com.XX*" scoped-proxy="targetClass">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
然后在applicationContext-mvc.xml中再扫描 Controller
<context:component-scan base-package="com.xx" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
如未按照这样的顺序扫描,就可能引起事务失效。
2017-10-06 追加:
其他增强类功能如 异步调用、AOP功能失效,大多是配置错误导致,Controller层装配了未增强的 raw Bean。
相关文章推荐
- 网上商城项目实战之需求分析
- java jni编译
- Java多线程 学习笔记(一)
- ubuntu下jdk/maven环境安装
- Java遍历JSON
- Spring(一)——总体介绍
- 关于安卓eclipse SDK下载不了的解决方法
- java 入门 第二季4
- 主activity报空指针异常java.lang.RuntimeException: Unable to resume activity
- Spring3中的@value注解
- spring <context:component-scan>使用说明
- java项目jsp中如何引用本地路径图片
- spring mvc控制器问题
- 简单的Java读取txt文件流,没有乱码
- 运用java语言求1到1000内所有的完数(带源程序)
- org.springframework.web.servlet.mvc.support.RedirectAttributes
- eclipse中一些常见svn图标的含义
- Java SE 7 新特性
- 第5条:避免创建不必要的对象
- selenium webdriver+java(test类模板)