spring 使用aop 缺少依赖包aspectjweaver.jar 和spring-aop.jar报错

spring 使用aop 缺少依赖包aspectjweaver.jar 和spring-aop.jar报错运行后报了一大堆错误,挺吓人的,不要怕,这写错误可能是同一原因在不同地方重复出现;错误太长,粘贴几段,分析一下Exceptionencounteredduringcontextinitialization-cancellingrefreshattempt:org.springframework.beans.factory.BeanCreationException:Er…

运行后报了一大堆错误,挺吓人的,不要怕,这写错误可能是同一原因在不同地方重复出现;

错误太长,粘贴几段,分析一下

Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error

creating bean with name ‘loginLogDao’ defined in file [D:\actionSpring\chapter\chapter1\target\classes\com\smart\dao\LoginLogDao.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name ‘org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0′: Cannot resolve reference to bean ‘serviceMethod’ while setting bean property ‘pointcut’; nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name ‘serviceMethod’: Failed to introspect bean class [org.springframework.aop.aspectj.AspectJExpressionPointcut] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
九月 19, 2018 11:43:19 上午 org.springframework.test.context.TestContextManager prepareTestInstance
严重:

Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@bc05a6] to prepare test instance [com.smart.service.UserServiceTest@729b1e]
java.lang.IllegalStateException: Failed to load ApplicationContext

 

Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0′:

Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

刚开始可能云里雾里的,从上到下,分析一下黑体部分,发现了关键问题:j

springframework.aop.aspectj.AspectJExpression Pointcut for lookup method metadata: could not find class that it depends on

Pointcut 使用时,寻找方法时找不到依赖的类

java.lang.IllegalStateException: Failed to load ApplicationContext

发现问题出在配置文件上,查一下applicationContect.xml且和aop:pointcut有关,发现:

<!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->
<aop:config proxy-target-class="true">
    <aop:pointcut id="serviceMethod"
                  expression=" execution(* com.smart.service..*(..))" />
    <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
</aop:config>

使用时需要依赖于一些第三方库

java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

找到缺少的类包weaver

下载aspectjweaver.jar ,网上很多资源,附一个下载链接

导入该依赖包

有些人可能还缺少spring-aop.jar,这个一般使用IDE导入spring框架会有。

另附:spring官方文档

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/36103.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注