error at ::0 can't find referenced pointcut annotation

随声附和 提交于 2019-12-01 23:46:32

问题


I am trying to create an aspect to monitor the time execution of certain methods. When I tried to run the test I get this error:

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)

when the ApplicationContext is loading.

I define the annotation as:

@Retention(RetentionPolicy.RUNTIME)
@Target(
{
    ElementType.METHOD, 
    ElementType.TYPE
})
public @interface TimePerformance {

}

And this is the aspect code:

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

    }


}

And the configuration is:

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

I just checked many questions here, but most of them gives as solution use the version 1.7 of aspectj. I am using:

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

Other solution point to the name of the variable in the method signature, but as you can see there is no error on that.

Does anyone any idea about where is the problem?

Thanks


回答1:


You are simply missing a @ in front of annotation in your pointcut.

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



回答2:


I solve the problem using this configuration in the aspect class

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

But the problem now, the aspect is not being executed.



来源:https://stackoverflow.com/questions/21279716/error-at-0-cant-find-referenced-pointcut-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!