:: 0处的错误无法找到引用的切入点注释
我正在尝试创建一个方面来监视某些方法的执行时间。 当我尝试运行测试时,我收到此错误:
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; } }
配置是:
我刚刚在这里检查了很多问题,但是大多数问题都提供了解决方案使用版本1.7的aspectj。 我在用:
org.aspectj aspectjrt 1.7.0 org.aspectj aspectjweaver 1.7.0
其他解决方案指向方法签名中变量的名称,但正如您所看到的那样,没有错误。
有谁知道问题出在哪里?
谢谢
您只是在切入点中的annotation
前面缺少@
。
@Around("anyPublicMethod() && @annotation(timePerformance)") ^
我在方面类中使用此配置解决了问题
@Around("execution(* *(..)) && @annotation(timePerformance)") public Object timePerformance(ProceedingJoinPoint pjp, TimePerformance timePerformance) throws Throwable
但现在问题是,方面没有被执行。