前几天在学习到了Spring3.0.2的AOP部分,当时教程上使用的是Spring2.5.0,然后配置自定义的切入点函数(pointcut),在junit中测试正常通过,然后本人在Spring3.0.2下测试,缺报错,信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDAOImpl' defined in file [G:\JAVA\SPCCE\Spring_1500_AOP_Annotation_avin\bin\com\bjsxt\dao\impl\UserDAOImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut avinMethod
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at 
.....主要是第一行中,显示找不到自定义的切入点函数avinMethod,后来我以为是配置部分有误,就直接把教程中的源代码放到切面类(aspect)LogInterceprot中调用! 结果依旧,对比了MyEclipse中的Spring框架与教程中的以后,觉得应该是jar包的问题,同时也不排除框架本身的不兼容性,应为无论是2.5.0还是3.0.2的Spring都在AOP的时候用到了aspectjrt.jar  aspectjweaver.jar,由此思路,开始寻找匹配的aspect组合,从csdn的论坛上看到一篇大同小异的文章链接如下:
http://fantasy0707.javaeye.com/category/101674?show_full=true帖子中作者同样自定义的@pointcut函数,框架为Spring3.0.2,文中作者提到,要使aspectj正常工作,还需要几个其他的包,依次如下:
aspectjrt.jar
aspectjweaver.jar
aoplliance-1.0.jar
org.springframework.asm-3.0.2.RELEASE.jar
asm-all-3.2.jar
cglib-nodep-2.1.3.jarSpring中的相关包:commons-logging-1.1.1.jar
org.springframework.beans-3.0.2.REALEASE.jar
org.springframework.context-3.0.2.RELEASE.jar
org.springframework.context-support-3.0.2.RELEASE.jar
org.springframework.core-3.0.2-RELEASE.jar
org.springframework.expression-3.0.2-RELEASE.jar
org.springframework.aspects-3.0.2-RELEASE.jar
org.springframework.aop-3.0.2-RELEASE.jar依帖子中的配置,集齐了jar包之后就开工了,结果很正常,报错依旧!
用文中作者的配置,在测试@before正常,然后考虑是不是文中作者列举的Jar包邮版本更新,然后去google分别下载了各自最新的jar包,拼凑起来,还是报错!
然后各交流群求助,未果! 继续沿着jar包的方向寻找解决方案……
后来在一个外国论坛上也看到了几乎同样的问题求助,不过下面的解决建议都是类似换框架,就是将Spring3.0.2换成2.5.0 或者更改MyEclipse的编译环境版本,均试下,未果……
论坛地址:http://www.techinfopad.com/spring/100701686-cant-find-referenced-pointcut-in-java-6.html
带着问题,继续学习Spring3.0.2的xml配置部分,好奇的将@pointcut用XML声明,结果测试通过! aspect class被调用,成功在目标函数之前引入逻辑,
这让我看到了希望,至少XML还可以实现同样的功能,接着是Spring3.0.2的DataSource,其中用到了Jakarta commons的包,当时本子电量告罄,不得不来日再战,
翌日,在网上找jakarta commons的包,还不少,google的时候无意中发现了一个下载jar包的网站,里边jar包相当齐全,不但顺利下载玩jakarta commons的相关包,还把前几天很难找到的aspectjrt.jar  aspectjweaver.jar aspectjtools.jar找到,顺便也都下载了,然后整合到本子上又开始测试前几天那个错误! 因为最开始的那篇csdn的帖子中,作者确实是实现了用annotation的方式声明并调用@pointcut自定义切入点函数:aspect method,所以希望总是存在!今天把希望寄托在aspectjtools.jar上,因为前几次测试无论是换包,换代码,都没有涉及到此包……
测试开始……******************************************************
第一轮测试,Junit测试未通过,显示缺少jar包,尽管没通过,至少是给了提示,如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor
at ........第一行得知,缺少aoplliance.jar 导入,再测……
******************************************************************
提示缺少xerces.jar 转机出现在这里,在寻找xerces.jar的时候,看到一篇帖子,上面大致意思是说,尽量使用Spring本身提供的jar包,这样可以减少bao这件的排斥性,即不兼容,想了想,也是,找到xerces.jar 导入,再测……******************************************************************
未果……错误代码没有找到有用信息。看来aspectjtools包并没有起作用!
这时候想起了刚才看到的建议,然后又进jar库,无意间发现了一个org.aspectj.aspectjweaver_1.5.3.jar的包,随便把它加了进去,导入
项目,测试开始……
*********************************************************************Junit测试进度条显示绿色,测试通过,逻辑被调用,切入面工作正常……
日志输出如下:2010-11-3 17:33:24 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@182f0db: startup date [Wed Nov 03 17:33:24 CST 2010]; root of context hierarchy
2010-11-3 17:33:24 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
2010-11-3 17:33:25 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1df280b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,logInterceptor,userDAOImpl,userService,org.springframework.aop.config.internalAutoProxyCreator]; root of factory hierarchy
before method...Avin hello!
user saved!--This is DAOImpl1
**************************************************************
最后两行的为具体的输出信息,最后一行是目标函数的输出信息,倒数第二行是切面中的逻辑! 幸运落在了最后的jar包上:org.aspectj.aspectjweaver.jar经几天测试得到的正确匹配Jar包列表如下:
org.springframework.beans-3.0.2.REALEASE.jar
org.springframework.context-3.0.2.RELEASE.jar
org.springframework.context-support-3.0.2.RELEASE.jar
org.springframework.core-3.0.2-RELEASE.jar
org.springframework.expression-3.0.2-RELEASE.jar
org.springframework.aspects-3.0.2-RELEASE.jar
org.springframework.aop-3.0.2-RELEASE.jar
commons-logging-1.1.1.jarjunit-4.9-SNAPSHOT-20100512-0041.jar
aspectjrt-111.jar
asm-all-3.2.jar
cglib-nodep-2.1.3.jar
aoplliance-1.0.jar
org.springframework.asm-3.0.2.RELEASE.jar
org.aspectj.aspectjweaver_1.5.3.jar
测试至此结束,问题解决……
希望能给遇到此问题的人一些思路……
***************************************总结:
1.j2ee中很多框架之间存在着错综复杂的jar包依赖关系(估计可以和linux里边的rpm依赖媲美了……解决依赖关系的方法大多是寻找正确匹配的jar包,这里向大家提供跟两个jar包的下载网站:http://www.java2s.com/http://www.findjar.com/jar/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar.html 2.CSDN很优秀,很多技术性的文章写得很有针对性!学习交流的好地方!
3.Google资料相较于Baidu多很多,尤其是外国技术资料!
4.遇到报错时,冷静分析,找到可能的切入点,保持冷静,清醒!
5.当确定方向正确时,坚持下去!
6.记住,豆芽长一房高,也是根菜!我们要鄙视敌人! 呵呵! 好,关于这个问题就写这么多,希望对大家有帮助……
同时也期待各位的相互交流指点……