日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

spring aop 如何切面到mvc 的controller--转载

發(fā)布時間:2025/4/5 c/c++ 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring aop 如何切面到mvc 的controller--转载 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

原文:http://yjian84.iteye.com/blog/1920787

網(wǎng)上搜羅半天,不知道什么原因,看了源碼,好像他們說的controller 是不受代理的,也對哈,不知道怎么辦,于是在http://stackoverflow.com/questions/17834958/spring-aop-is-not-working-in-with-mvc-structure?rq=1 這個地方有個人說了:?

<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.?


這個人說的好像很對啊。我把a(bǔ)spectj 和springmvc的配置文件放到一起就可以用到controller上了。?

spring-mvc.xml?

<context:component-scan base-package="com.cms.controller" /><context:component-scan base-package="com.cms.aspectj" /><!-- <bean id="sysLogAspectJ" class="com.cms.aspectj.SysLogAspectJ" /> --><aop:aspectj-autoproxy proxy-target-class="true"><!-- <aop:include name="sysLogAspectJ" /> --></aop:aspectj-autoproxy><!-- <mvc:annotation-driven /> --><beanclass="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /><beanclass="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> package com.cms.aspectj;import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component;@Component @Aspect public class SysLogAspectJ {@Pointcut("within(@org.springframework.stereotype.Controller *)")public void cutController(){}@Around("cutController()")public Object recordSysLog(ProceedingJoinPoint point) throws Throwable{System.out.println("lfkdjj================================================================");return point.proceed();}}

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/4121765.html

總結(jié)

以上是生活随笔為你收集整理的spring aop 如何切面到mvc 的controller--转载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。