Spring AOP异常:Error creating bean with name ‘org.springframework.aop.aspectj.

时间:2022-07-22
本文章向大家介绍Spring AOP异常:Error creating bean with name ‘org.springframework.aop.aspectj.,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

异常:

Jul 26, 2020 11:43:22 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4ee285c6: startup date [Sun Jul 26 11:43:22 CST 2020]; root of context hierarchy
Jul 26, 2020 11:43:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Jul 26, 2020 11:43:23 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
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)#4493d195' 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)#4493d195': Cannot resolve reference to bean 'selectAll' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'selectAll': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
Jerry ends here!

解决方案

右键单击项目,选择Configure build path->Add External Jars:

将这三个jar加到Build Path里:

错误消失:

aspectjrt.jar:The runtime needed to execute a program using AspectJ. 基于AspectJ库的应用运行时必须的运行库。

下载地址:https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.6.9

aspectjweaver.jar: The AspectJ weaver introduces advices to java classes,给Java类引入对advices的支持

下载地址:https://mvnrepository.com/artifact/org.aspectj/aspectjweaver

aopalliance.jar: The AOP Alliance aims to ensure interoperability between Java/J2EE AOP implementations to build a larger AOP community.

下载地址:https://sourceforge.net/projects/aopalliance/