spring事务增强功能未实现原因
问题描述
单独使用测试类加载spring-mybatis
整合配置文件可以实现aop
增强功能,同时加载spring-mybatis
和springMVC
配置文件整合aop
增强功能失效。
测试方法
单独使用一个ssm
整合配置文件可以实现aop
增强功能。
原因分析
说明web
容器加载完spring-mybatis
配置文件后,在springMVC
配置文件加载ioc
容器时覆盖了service
类在ioc
容器中的bean
实例
测试方法
使用两个配置文件,同时spring-mybatis
添加
<context:component-scan base-package="com.nerber" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
springMVC
配置文件添加
<context:component-scan base-package="com.nerber" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
以上配置可以实现aop
增强
当springMVC
中不使用
user-default-filters="false"
无法实现aop增强。
配置文件中都使用exclude-filter时,也可以实现aop增强。
原因分析
include-filter需要和use-default-filters结合使用才能生效