Java springaop@annotation
我是AOP的新手,尤其是在春季AOP 我想用某种特定的方法记录执行时间。我阅读了Spring文档 并认为最好的解决方案是创建带有注释切入点的方面 它看起来像:Java springaop@annotation,java,spring,aop,Java,Spring,Aop,我是AOP的新手,尤其是在春季AOP 我想用某种特定的方法记录执行时间。我阅读了Spring文档 并认为最好的解决方案是创建带有注释切入点的方面 它看起来像: @Around("@annotation(com.x.y.MethodExecutionTime)") public Object methodExecutionTimeLog(ProceedingJoinPoint joinPoint) throws Throwable StopWatch stopWatch = new St
@Around("@annotation(com.x.y.MethodExecutionTime)")
public Object methodExecutionTimeLog(ProceedingJoinPoint joinPoint) throws Throwable
StopWatch stopWatch = new StopWatch();
Object retVal = null;
try {
stopWatch.start();
retVal = joinPoint.proceed();
stopWatch.stop();
logger.info("Execution time: " + stopWatch.getTotalTimeMillis() + " ms");
} catch(Throwable e) {
logger.error("Execution time: " + stopWatch.getTotalTimeMillis() + " ms");
throw e;
}
return retVal;
}
注释用于方法:
@Override
@MethodExecutionTime
public <T> T copy(Class<T> destType) {
T t = ReflectionHelper.newInstance(destType);
copyTo(t);
return t;
}
@覆盖
@方法执行时间
公共T型副本(类别类型){
T=ReflectionHelper.newInstance(destType);
copyTo(t);
返回t;
}
Spring XML配置:
<context:spring-configured />
<aop:aspectj-autoproxy proxy-target-class="true" />
但它什么也不记录
我正在使用Spring3.0.5
有什么想法吗?谢谢如果其他所有配置都正确,那么它应该是Spring AOP的限制之一(至少是默认配置的限制),即:
- 要应用方面的对象应由Spring管理(即,它应该从应用程序上下文中获取,而不是使用
创建)new
- 调用应该起源于该对象的“外部”,即当您调用同一对象的另一个方法时,不会应用方面
应该在与要应用方面的对象相同的应用程序上下文中声明(特别是在典型的SpringWebMVC应用程序中,
和applicationContext.xml
形成不同的应用程序上下文)…-servlet.xml
@Aspect
注释了@Around
方法的类?它是Spring应用程序上下文的一部分吗?MethodExecutionTime
Annotation的保留类型是什么?是运行时吗?嗨,axtavt,你能看看我在SpringAOP上的帖子吗-