我是AOP的新手,特别是Spring AOP。Spring AOP @annotation
我想用某种特定的方法记录执行时间。我阅读Spring文档 并认为最好的解决方案是创建带注释切入点的方面。
它看起来像:
@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;
}
Spring XML配置:
<context:spring-configured />
<aop:aspectj-autoproxy proxy-target-class="true" />
,但它会记录什么。
我正在使用Spring 3.0.5
任何想法?由于
你能后的代码使用这个注解?你可以发布Spring Spring AOP的设置吗? –
您是否在春季xml中启用了aop?显示与aop相关的xml spring配置的一部分。 –
我发布了它,是否有必要添加一些其他选项到Spring XML配置文件? – vlcik