【发布时间】:2014-01-22 10:03:57
【问题描述】:
我正在尝试创建一个方面来监控某些方法的执行时间。当我尝试运行测试时,出现此错误:
Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut annotation
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
ApplicationContext 加载时。
我将注解定义为:
@Retention(RetentionPolicy.RUNTIME)
@Target(
{
ElementType.METHOD,
ElementType.TYPE
})
public @interface TimePerformance {
}
这是方面的代码:
@Aspect
public class MonitorImpl{
private static final Log LOG = LogFactory.getLog(MonitorImpl.class);
@Pointcut(value="execution(public * *(..))")
public void anyPublicMethod() { }
@Around("anyPublicMethod() && 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>
我刚刚在这里检查了很多问题,但大多数问题都使用 aspectj 的 1.7 版本作为解决方案。我正在使用:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.0</version>
</dependency>
其他解决方案指向方法签名中变量的名称,但您可以看到没有错误。
有人知道问题出在哪里吗?
谢谢
【问题讨论】:
标签: java spring annotations aop spring-aop