我是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