Skip to content

Improve failure metadata that is available from BeanInstantiationException [SPR-14166] #18738

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 7e55b08

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions