Spring系列: 使用aop报错:nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/Ref...


写了个最简单的aop例子
配置文件如下
 
   
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:c="http://www.springframework.org/schema/c"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:p="http://www.springframework.org/schema/p"
  8. xmlns:util="http://www.springframework.org/schema/util"
  9. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  10. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
  11. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  12. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
  13. <aop:config>
  14. <aop:aspect ref="logger">
  15. <aop:pointcut id="dbmethod" expression="execution(* com.cet.peccore.DbInterfaceForPG.SetupTableForPG.*(..))" />
  16. <aop:before pointcut-ref="dbmethod" method="LogBefore" />
  17. <aop:after pointcut-ref="dbmethod" method="LogAfter" />
  18. </aop:aspect>
  19. </aop:config>
  20. <bean id="dbInterface" class="com.cet.peccore.DbInterface.DbInterface" autowire="byType"/>
  21. <bean id="setupTable" class="com.cet.peccore.DbInterfaceForPG.SetupTableForPG"/>
  22. <bean id="logger" class="com.cet.peccore.PecTrend.util.MyLogger"/>
  23. </beans>
但是运行的时候总是报如下错误:
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#29daf3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#29daf3': Cannot resolve reference to bean 'dbmethod' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbmethod': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#29daf3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#29daf3': Cannot resolve reference to bean 'dbmethod' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbmethod': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException  


原因:是由于classpath下缺少了aspectjweaver.jar的缘故。
解决办法:在pom.xml中加入依赖信息
Xml代码   收藏代码
  1. <dependency>  
  2.        <groupId> org.aspectj</groupId >  
  3.        <artifactId> aspectjweaver</artifactId >  
  4.        <version> 1.8.7</version >  
  5. </dependency>  
     




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是由于缺少Spring Framework的相关依赖包导致的。具体来说,缺少org.springframework.util.AntPathMatcher$AntPatternComparator类所在的包。解决这个问题的方法是手动导入相关的包或者使用构建工具(如Maven或Gradle)来管理依赖关系。如果你选择手动导入包,可以按照引用中提供的依赖关系添加以下包: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>5.3.9</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.3.9</version> <scope>test</scope> </dependency>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值