今天要写一个Spring的切面测试,本意是想一刀切到所在bean的包下,然后查看这些bean被代理的情况。由于是测试环境,我图省事儿就把所有的class都放在同一个路径下了,然后BlueAspect切面中的pointcut表达式直接切向了slg.aop.aspect包下的所有类。
结果直接带来了血淋淋的后果:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘blueAspect’ defined in com.enjoy.slg.aop.MyConfig3: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.enjoy.slg.aop.BlueAspect]: Factory method ‘blueAspect’ threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘blueAspect’: Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1254)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.(AnnotationConfigApplicationContext.java:88)
at com.enjoy.slg.aop.MyConfig3.main(MyConfig3.java:33)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.enjoy.slg.aop.Book]: Factory method ‘book’ threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘blueAspect’ defined in com.enjoy.slg.aop.MyConfig3: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.enjoy.slg.aop.BlueAspect]: Factory method ‘blueAspect’ threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘blueAspect’: Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
… 13 more
因为这个pointcut不光切了我想要代理的bean,也同时毫不留情的把刀挥向了自己(Aspect类也在slg.aop.aspect这个包下)……所以说练功需谨慎,没事儿别自宫