错误在:: 0无法找到引用的切入点注释

时间:2014-01-22 10:03:57

标签: java spring annotations aop spring-aop

我正在尝试创建一个方面来监视某些方法的执行时间。当我尝试运行测试时出现此错误:

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>

我刚刚在这里检查了很多问题,但是大多数问题都提供了解决方案使用版本1.7的aspectj。我正在使用:

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

其他解决方案指向方法签名中变量的名称,但正如您所看到的那样,没有任何错误。

有谁知道问题出在哪里?

由于

2 个答案:

答案 0 :(得分:9)

您在切入点@前面错过了annotation

@Around("anyPublicMethod() && @annotation(timePerformance)")
                              ^

答案 1 :(得分:0)

我在方面类

中使用此配置解决了问题
@Around("execution(* *(..)) && @annotation(timePerformance)")
public Object  timePerformance(ProceedingJoinPoint pjp, TimePerformance timePerformance) throws Throwable 

但现在问题是,方面没有被执行。