引起:java.lang.IllegalArgumentException::: 0处的错误找不到引用的切入点

时间:2013-10-20 15:45:19

标签: java spring aop spring-aop

使用Pointcut for Spring AOP不起作用,否则效果很好。 请帮我解决这个问题。

没有Pointcut工作代码:

@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");
}

使用Pointcut代码会出错:

@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()
{

}

例外:

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配置文件:

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

2 个答案:

答案 0 :(得分:3)

this post看来,旧版本的运行时AspectJ jar发生错误。升级到aspectjrt的最新版本,即1.7.3

答案 1 :(得分:0)

有时因为aspectj jar的版本冲突会引起我的问​​题。我刚刚删除了aspectjtools依赖,更新了aspectjrt,aspectjweaver到最新版本,它解决了我的问题