I am trying to create an aspect to control the 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 ApplicationContext loads.
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:
<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 a lot of questions here, but most of them give a solution to use aspectj version 1.7. I use:
<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>
Another solution points to the variable name in the method signature, but as you can see, there is no error.
Does anyone know where the problem is?
thanks
ftrujillo
source share