spring aop 如何切面到mvc 的controller--转载
原文:http://yjian84.iteye.com/blog/1920787
網(wǎng)上搜羅半天,不知道什么原因,看了源碼,好像他們說(shuō)的controller 是不受代理的,也對(duì)哈,不知道怎么辦,于是在http://stackoverflow.com/questions/17834958/spring-aop-is-not-working-in-with-mvc-structure?rq=1 這個(gè)地方有個(gè)人說(shuō)了:?
<context:component-scan base-package="com.dao" />?
<mvc:annotation-driven/>?
<aop:aspectj-autoproxy />???
from application-context.xml to controller-servlet.xml??
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.?
這個(gè)人說(shuō)的好像很對(duì)啊。我把a(bǔ)spectj 和springmvc的配置文件放到一起就可以用到controller上了。?
spring-mvc.xml?
?
轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/4121765.html
總結(jié)
以上是生活随笔為你收集整理的spring aop 如何切面到mvc 的controller--转载的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring AOP + AspectJ
- 下一篇: spring mvc Dispatche