Tag Archives: Spring Aop error

[Solved] Spring Aop Error: Error creating bean with name ‘org.springframework.aop.config.internalAutoProxyCreator‘

Make a simple entry case of spring AOP, and the following error reports are generated at runtime

12月 06, 2021 9:26:16 PM org.springframework.context.support.AbstractApplicationContext refresh
Warning: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils$MethodFilter.and(Lorg/springframework/util/ReflectionUtils$MethodFilter;)Lorg/springframework/util/ReflectionUtils$MethodFilter;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils$MethodFilter.and(Lorg/springframework/util/ReflectionUtils$MethodFilter;)Lorg/springframework/util/ReflectionUtils$MethodFilter;

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:229)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:722)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
	at com.atguigu.spring5.testdemo.TestAop.testAopAnno(TestAop.java:11)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils$MethodFilter.and(Lorg/springframework/util/ReflectionUtils$MethodFilter;)Lorg/springframework/util/ReflectionUtils$MethodFilter;
	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.<clinit>(ReflectiveAspectJAdvisorFactory.java:76)
	at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.initBeanFactory(AnnotationAwareAspectJAutoProxyCreator.java:82)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.setBeanFactory(AbstractAdvisorAutoProxyCreator.java:65)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1818)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1783)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
	... 33 more

Check some big guys’ articles until the problem is called: injection bean failure exception.

After checking, it is found that it is caused by the inconsistent version of the jar package. The version of spring I use is 5.3 13. Before, in order to save trouble, we directly copied other people’s core jar package, and its version was 5.2 6. I changed the versions of these four jar packages to 5.3.0, which is consistent with the spring version 13. The problem is solved

Modified jar package:

There is also a small problem. When using the pointcut expression, there must be a space between * and the following com, otherwise an error will be reported

@Before(value = "execution(* com.testAop.anno.User.add(..))")

[Solved] Spring AOP Error creating bean with name

When learning the AOP configuration of spring, I encountered an error as follows:

Warning: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/jeremy/service/userServiceImpl (wrong name: com/jeremy/service/UserServiceImpl)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/jeremy/service/userServiceImpl (wrong name: com/jeremy/service/UserServiceImpl)

An error occurred when creating the bean because the class NoClassDefFoundError could not be found

Cause of the problem: the class name of pointcut configured in execution is filled in lowercase by mistake, so an error is reported
solution: change the class name to the correct uppercase

    <aop:config>
        <aop:pointcut id="pointcut" expression="execution(* com.jeremy.service.userServiceImpl.*(..))"/>

        <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
        <aop:advisor advice-ref="beforeLog" pointcut-ref="pointcut"/>
    </aop:config>

Change to

 <aop:config>
     <aop:pointcut id="pointcut" expression="execution(* com.jeremy.service.UserServiceImpl.*(..))"/>

     <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
     <aop:advisor advice-ref="beforeLog" pointcut-ref="pointcut"/>
 </aop:config>

Spring Aop error creating bean with name ‘org.springframework.aop.config.internalAutoProxyCreator

In addition to spring AOP jar package, spring AOP should also be included in spring AOP programming aspectjrt.jar , aspectjweaver.jar , and aopalliance_ 1.0.jar, otherwise an error is reported:

org.springframework.beans . factory.BeanCreationExcspring -aopeption: 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

 

aopalliance_ 1.0.jar download address:

http://mirrors.ibiblio.org/pub/mirrors/maven2/aopalliance/aopalliance/1.0/