AOP拦截不到Controller中的方法
原因:
The aspects and the beans to be applied needs to be in the same ApplicationContext but ApplicationContext is not aware of WebApplicationContext .
Indeed your controller (annotated by @Controller) and your aspects (annotated by @Aspect) should be in the same Spring context.
Usually people define their controllers in the dispatch-servlet.xml or xxx-servlet.xml and their service beans (including the aspects) in the main applicationContext.xml. It will not work.
When Spring initializes the MVC context, it will create a proxy for your controller but if your aspects are not in the same context, Spring will not create interceptors for them.
处理方案:
需要把AOP的配置放在SpringMVC的Context中
dispatcher-servlet.xml
<!-- 记录操作日志 -->
<aop:config>
<aop:advisor id="submitTx" advice-ref="txSubmitAdvice"
pointcut="execution(* *..controller.*Controller.onSubmit(..))" order="0" />
</aop:config>
<bean id="txSubmitAdvice" class="com.disappearwind.service.SubmitAdvice"/>

浙公网安备 33010602011771号