You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getBean(Object.class) fails when introspecting Environment bean [SPR-10542] #15172
in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug
Trying to access a bean of type Object gives the backtrace:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'environment' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:264)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1125)
at Test.main(Test.java:7)
There are several internal infrastructure beans registered by default with the context so calling applicationContext.getBean(Object.class) does not make much sense (but admittedly the error message is not great).
If I remember correctly, I was writing an integration test where the contents of the ApplicationContext were unimportant. I admit that I can't think of terribly many use cases for this ;)
Even if this is an unlikely use case, getBean(Class) needs to be able to handle singletons beans without a backing bean definition as well, if they turn out to be a type match...
Fixed for 4.1 GA through an additional containsBeanDefinition check, leading to a proper NoUniqueBeanDefinitionException. To be backported to 4.0.7 and 3.2.11 as well.
in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug
Activity
spring-projects-issues commentedon Jul 2, 2013
Phil Webb commented
There are several internal infrastructure beans registered by default with the context so calling
applicationContext.getBean(Object.class)does not make much sense (but admittedly the error message is not great).What are you trying to achieve with this call?
spring-projects-issues commentedon Jul 3, 2013
James Shaw commented
If I remember correctly, I was writing an integration test where the contents of the ApplicationContext were unimportant. I admit that I can't think of terribly many use cases for this ;)
spring-projects-issues commentedon Aug 20, 2014
Juergen Hoeller commented
Even if this is an unlikely use case, getBean(Class) needs to be able to handle singletons beans without a backing bean definition as well, if they turn out to be a type match...
Juergen
spring-projects-issues commentedon Aug 20, 2014
Juergen Hoeller commented
Fixed for 4.1 GA through an additional containsBeanDefinition check, leading to a proper NoUniqueBeanDefinitionException. To be backported to 4.0.7 and 3.2.11 as well.
Juergen