sunleo sunleo - 1 month ago 11
Java Question

Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut

Using Pointcut for Spring AOP is not working otherwise it works well.
Please help me to solve this issue.

Without Pointcut working code :

@Before("execution(public * spring.beans.Triangle.set*(*))")
public void beforeonlySetTriangle_FirstAspect()
{
System.out.println("beforeonlySetTriangle_FirstAspect only for Triangle is called");
}
@Before("execution(public * spring.beans.Triangle.set*(*))")
public void beforeonlySetTriangle_SecondAspect()
{
System.out.println("beforeonlySetTriangle_SecondAspect only for Triangle is called");
}


With Pointcut code gives error:

@Before("setTrianglePointCutter()")
public void beforeonlySetTriangle_FirstAspect()
{
System.out.println("beforeonlySetTriangle_FirstAspect only for Triangle is called");
}
@Before("setTrianglePointCutter()")
public void beforeonlySetTriangle_SecondAspect()
{
System.out.println("beforeonlySetTriangle_SecondAspect only for Triangle is called");
}

@Pointcut("execution(public * spring.beans.Triangle.set*(*))")
public void setTrianglePointCutter()
{

}


Exception :

Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut setTrianglePointCutter
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:317)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:193)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:182)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:163)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:209)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:263)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:295)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 11 more


spring.xml config file :

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">

<aop:aspectj-autoproxy />

<bean id="triangle" class="spring.beans.Triangle">
<property name="name" value="TriangleName"></property>
</bean>

<bean id="circle" class="spring.beans.Circle">
<property name="name" value="CircleName"></property>
</bean>

<bean id="shapeService" class="spring.service.ShapeService" autowire="byName"/>
<bean id="loggingAspect" class="spring.aspect.LoggingAspect" />


</beans>

Answer Source

It appears from this post that error occurs with old version of runtime AspectJ jars. Upgrade to the latest versions for the aspectjrt, i.e. 1.7.3