spring AOP执行2次
奇怪的是,我自己搭建的springmvc框架就只执行了一次,但是在项目中,主执行了2次。
为什么spring AOP执行2次?
1、去掉@Component就可以了。【是否去掉@Component,要看spring的其它配置,换个文件夹,没有@Component反而不会执行aop了。】
2、日志的原因,请参照:http://stackoverflow.com/questions/18731520/spring-aop-controller-executing-twice
http://stackoverflow.com/questions/11516092/spring-aop-advice-called-twice
部分代码如下:
/** * * @author arthur.paincupid.lee * @since 2016.04.17 */@Aspect@Componentpublic class SysLogWithOutAnn { private static final Logger logger = LoggerFactory .getLogger(SysLogWithOutAnn.class); private static String[] types = { "java.lang.Integer", "java.lang.Double", "java.lang.Float", "java.lang.Long", "java.lang.Short", "java.lang.Byte", "java.lang.Boolean", "java.lang.Char", "java.lang.String", "int", "double", "long", "short", "byte", "boolean", "char", "float" }; @Pointcut("execution(* com.paincupid.springmvc.*.controller.*.search*(..))") public void searchControllerCall() { } @AfterRetuing(value = "searchControllerCall()", argNames = "rtv", retuing = "rtv") public void searchControllerCallCalls(JoinPoint joinPoint, Object rtv) throws Throwable { System.out.println("---------------"); String classType = joinPoint.getTarget().getClass().getName(); Class<?> clazz = Class.forName(classType);
I don't annotate aspects with @Component annoation, try to remove it, maybe because of that is being processed twice by Spring.
参考:http://stackoverflow.com/questions/7900905/spring-aop-advice-is-called-twice
http://stackoverflow.com/questions/18731520/spring-aop-controller-executing-twice
http://stackoverflow.com/questions/11516092/spring-aop-advice-called-twice
转载请注明出处:http://blog.csdn.net/paincupid/article/details/51190501
作者:arthur.dy.lee
来源链接:https://blog.csdn.net/paincupid/article/details/51190501
版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。
2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。