在使用springMVC+spring+mybatis开发一个项目的时候,对整个项目进行事务管理,但是一直aop没有拦截到连接点,用了一天的功夫在网上寻找答案
在这个地址找到了答案
解决的方法是,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就不能发挥作用了。

本文介绍了解决Spring MVC项目中AOP未正确拦截连接点的问题,通过调整扫描范围确保Controller层由Spring MVC管理,而Service层则由Spring进行扫描,从而实现有效的事务管理。
173万+





