您的位置:首页 > 编程语言 > Java开发

springMVC与spring使用中,AOP失效的问题

2017-03-06 17:41 435 查看
在使用springMVC+spring+mybatis开发一个项目的时候,对整个项目进行事务管理,但是一直aop没有拦截到连接点,用了一天的功夫在网上寻找答案

在这个地址找到了答案

http://www.cnblogs.com/wcyBlog/p/4342077.html

解决的方法是,springMVC只扫描controller层的包,spring不扫描controller的包
<!-- 在springMVC -->
<context:component-scan base-package="com">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>

<!-- 在spring -->
<context:component-scan base-package="com">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>


详细的原因是,springMVC会先扫描加载,当springMVC扫描后,扫描过的部分,spring就不会去扫描了,于是spring中的AOP就不能发挥作用了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: