Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: AbstractBeanDefinition.getBeanClass() vs BeanFactory.getType #24816

Closed
anLA7856 opened this issue Mar 30, 2020 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Milestone

Comments

@anLA7856
Copy link

Affects: all version

I try to know the beanClass of BeanDefinition, however, I found some subClass of BeanDefinition has no beanClass.
Such as ConfigurationClassBeanDefinition in ConfigurationClassBeanDefinitionReader, when ConfigurationClassPostProcessor parse @Bean method to a BeanDefinition(ConfigurationClassBeanDefinition), whose beanClass field is null.
So far as I know, beanClass stand for it's bean type.
I wan to know why beanClass in BeanDefinition can be null, and how I get it's bean type from some of it's subClass.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 30, 2020
@jhoeller jhoeller changed the title Why can beanClasss in subClass of BeanDefinition be null Documentation: BeanDefinition.getBeanClass() vs BeanFactory.getType Apr 1, 2020
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 1, 2020
@jhoeller jhoeller added this to the 5.2.6 milestone Apr 1, 2020
@jhoeller jhoeller changed the title Documentation: BeanDefinition.getBeanClass() vs BeanFactory.getType Documentation: AbstractBeanDefinition.getBeanClass() vs BeanFactory.getType Apr 1, 2020
@jhoeller
Copy link
Contributor

jhoeller commented Apr 1, 2020

AbstractBeanDefinition.getBeanClass() contains a resolved bean class name as specified in the original bean definition; this is just indirectly related to the bean's actual runtime type. A bean definition may point to a specific factory method on that bean class, returning a different type of bean, or it might declare a FactoryBean class for a different object type. The recommended way to find out about the actual runtime type of a particular bean is a BeanFactory.getType call for the specified bean name; this takes all of the above cases into account and returns the type of object that a BeanFactory.getBean call is going to return for the same bean name.

I've turned this into a documentation ticket since we should really have a bold note on this in the javadoc as well as the reference documentation. This is not as obvious as it should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants