我想創建一個方面來監視某些方法的時間執行。我定義註解爲:方法註釋不被執行
@Retention(RetentionPolicy.RUNTIME)
@Target(
{
ElementType.METHOD,
ElementType.TYPE
})
public @interface TimePerformance {
}
而這方面的代碼:
@Around("execution(* *(..)) && @annotation(timePerformance)")
public Object timePerformance(ProceedingJoinPoint pjp,TimePerformance timePerformance) throws Throwable {
if (LOG.isInfoEnabled()) {
LOG.info("AOP - Before executing "+pjp.getSignature());
}
Long startTime = System.currentTimeMillis();
Object result = pjp.proceed();
Long stopTime = System.currentTimeMillis();
LOG.info("MONITOR TIME_EXECUTION "+pjp.getSignature()+" : "+(stopTime-startTime));
if (LOG.isInfoEnabled()) {
LOG.info("AOP - After executing "+pjp.getSignature());
}
return result;
}
而配置是:
<!-- AOP support -->
<bean id='stateAspectImpl' class='eu.genetwister.snpaware.ui.aspect.StateAspectImpl' />
<bean id='monitorImpl' class='eu.genetwister.snpaware.monitor.MonitorImpl' />
<aop:aspectj-autoproxy>
<aop:include name='stateAspectImpl' />
<aop:include name='monitorImpl' />
</aop:aspectj-autoproxy>
我已經被註釋的方法(春季批量工作的一部分)像這樣:
@BeforeStep
@TimePerformance
public void retrieveInterstepData(StepExecution stepExecution)
但是,即使該方法被執行,該方面也不會被執行。
有沒有人有關如何解決這個問題的想法?
感謝
爲什麼你需要在切入點表達式中執行(..)?我相信@Around(value = @annotation(<類的全名,包括包>))應該工作。 – Hrishikesh
使用你的方法@Around(「value = @annotation(.TimePerformance)」)給出了關於錯誤格式爲 –
ftrujillo
你能提一下這個異常嗎?它是什麼意思?它可能是Aspect不是一個組件或一個bean – Hrishikesh