::0 处的错误找不到引用的切入点注释 [英] error at ::0 can't find referenced pointcut annotation

查看:27
本文介绍了::0 处的错误找不到引用的切入点注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

加载 ApplicationContext 时.

when the ApplicationContext is loading.

我将注释定义为:

@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版作为解决方案.我正在使用:

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?

谢谢

推荐答案

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

I solve the problem using this configuration in the aspect class

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

但是现在的问题是,aspect 没有被执行.

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

这篇关于::0 处的错误找不到引用的切入点注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆