Skip to content

getBean(Object.class) fails when introspecting Environment bean [SPR-10542] #15172

Closed

Description

@spring-projects-issues

James Shaw opened SPR-10542 and commented

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)

See attached test case to reproduce.


Affects: 3.2.2

Attachments:

Issue Links:

Referenced from: commits 9d3d6d5, e89f18b, 21d0ce5

Backported to: 4.0.7, 3.2.11

Activity

  1. spring-projects-issues commented on Jul 2, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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?

  2. spring-projects-issues commented on Jul 3, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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 ;)

  3. spring-projects-issues commented on Aug 20, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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

  4. spring-projects-issues commented on Aug 20, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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

  5. added
    type: bug
    status: backported
    in: core
    on Jan 11, 2019
  6. added this to the 4.1 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: backportedtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions