Closed
Description
Andy Wilkinson opened SPR-14166 and commented
This is a follow on from #18540.
I have just encountered a NoUniqueBeanDefinitionException
that was the cause of a BeanInstantiationException
:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration$$EnhancerBySpringCGLIB$$a2ce2574]: Constructor threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jmx.export.MBeanExporter] is defined: expected single matching bean but found 2: mbeanExporter,endpointMBeanExporter
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:841) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765) [classes/:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1182) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1171) [classes/:na]
at com.example.Gh5682Application.main(Gh5682Application.java:12) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration$$EnhancerBySpringCGLIB$$a2ce2574]: Constructor threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jmx.export.MBeanExporter] is defined: expected single matching bean but found 2: mbeanExporter,endpointMBeanExporter
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
... 17 common frames omitted
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jmx.export.MBeanExporter] is defined: expected single matching bean but found 2: mbeanExporter,endpointMBeanExporter
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:172) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1059) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfAvailable(DefaultListableBeanFactory.java:1544) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
at org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration.<init>(SpringApplicationAdminJmxAutoConfiguration.java:63) ~[classes/:na]
at org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration$$EnhancerBySpringCGLIB$$a2ce2574.<init>(<generated>) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_60]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_60]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
... 19 common frames omitted
For Boot's failure analysis, it would be useful to be able to access the Constructor
that was called from the BeanInstantiationException
.
Affects: 4.3 RC1
Issue Links:
- Improve core container exception meta-data [SPR-13968] #18540 Improve core container exception meta-data
- Improve exception when failing to create a specific bean due to a NoClassDefFoundError [SPR-14883] #19449 Improve exception when failing to create a specific bean due to a NoClassDefFoundError
Referenced from: commits 7e55b08