【问题标题】:error at ::0 can't find referenced pointcut annotation::0 处的错误找不到引用的切入点注释
【发布时间】: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


    【解决方案1】:

    您只是在切入点中的annotation 前面缺少@

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

    【讨论】:

      【解决方案2】:

      我在方面类中使用这个配置解决了问题

      @Around("execution(* *(..)) && @annotation(timePerformance)")
      public Object  timePerformance(ProceedingJoinPoint pjp, TimePerformance timePerformance) throws Throwable 
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多