Spring中採用annotation的方式實現AOP代理,運行測試代碼時拋出如下異常:java
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManager' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allAddMethod Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allAddMethod at org.aspectj.weaver.tools.PointcutParser.parsePointcutexpression_r(PointcutParser.java:315) at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression (AspectJExpressionPointcut.java:189) at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch (AspectJExpressionPointcut.java:176) at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter (AspectJExpressionPointcut.java:157) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:189) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:244) at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:278) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator .findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:83) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator .getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator .postProcessAfterInitialization(AbstractAutoProxyCreator.java:296) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:313) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .initializeBean(AbstractAutowireCapableBeanFactory.java:1181) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .createBean(AbstractAutowireCapableBeanFactory.java:427) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject (AbstractBeanFactory.java:249) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:155) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory .preInstantiateSingletons(DefaultListableBeanFactory.java:291) at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:352) at org.springframework.context.support.ClassPathXmlApplicationContext. (ClassPathXmlApplicationContext.java:122) at org.springframework.context.support.ClassPathXmlApplicationContext. (ClassPathXmlApplicationContext.java:66) at com.huang.spring.Client.main(Client.java:10)
本人詳細檢查過代碼和applicationContext.xml配置文件,發現並無錯!而其餘Spring項目能運行,所以出錯緣由能夠確定是aspectj兩個jar包的問題。網上不少說法是spring 2.0的版本中的的aspectjrt.jar和jdk不兼容,好吧,本人的JDK是1.7的,因而嘗試使用不一樣版本的aspectjrt.jar文件,發現錯誤仍然存在!因此不是aspectjrt.jar的問題。 因而本人下載了最新版本的aspectjweaver.jar並替換了原來的版本,error at ::0 can't find referenced pointcut allAddMethod成功解決了,程序正常運行。