spring AOP执行2次
2016-04-19 14:58
357 查看
奇怪的是,我自己搭建的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
部分代码如下:
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
转载请注明出处:/article/8545028.html
为什么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 @Component public 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() { } @AfterReturning(value = "searchControllerCall()", argNames = "rtv", returning = "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
转载请注明出处:/article/8545028.html
相关文章推荐
- spring事务管理几种方式
- Spring多数据源分布式事务管理/springmvc+spring+atomikos[jta]+druid+mybatis
- 集合
- java知识点2016.4.14
- Java内存泄露
- Java将数据导出到Excel
- 汉诺塔问题 Java 语言递归实现
- java.lang.IllegalStateException:Cannot add header view to list==setAdapter has already been called.
- JDK1.8新特性(java)
- IDEA 创建基于Maven的spring mvc框架
- java参数传递,引用还是拷贝
- Java多线程与静态方法
- Java_Ant详解
- java 1.8 函数式编程
- SpringMVC 使用对象接收参数
- Java学习·Set
- 乔治棍子算法JAVA实现
- Java的HashMap和HashTable
- Java回调机制解析
- Spring