Skip to content

Consider generics when predicting FactoryBean types #23338

Closed

Description

@philwebb

It would be beneficial if we could consider generics when trying to predict the result of FactoryBean.getObjectType(). We currently have difficulty with getBeanNamesForType if the bean being considered is a factory bean and we don't want to initialize it early.

It's possible that we can still deduce the type using generics of the factory method, or the class itself. For example:

@Bean
public FactoryBean<MyBean> myBean() {
    ...
}
public class MyFactoryBean implements FactoryBean<MyBean> {
    ...
}

We have logic to do this already as part of DefaultListableBeanFactory.getTypeForFactoryBean, however, in its current form that method may also cause early initialization of the bean.

Activity

  1. self-assigned this
    on Jul 23, 2019
  2. added
    in: coreIssues in core modules (aop, beans, core, context, expression)
    on Jul 23, 2019
  3. added this to the 5.2 RC1 milestone on Jul 23, 2019
  4. added 2 commits that reference this issue on Jul 23, 2019
    a3031ec
    45d1a62
  5. added a commit that references this issue on Jul 31, 2019
    71a5308
  6. added a commit that references this issue on Jul 31, 2019
    1b6a749
  7. philwebb commented on Jul 31, 2019

    @philwebb
    MemberAuthor

    I found an annoying edge case that means any @Configuration class picked up by component scanning won't be detected correctly. This is because the bean definition has a String type not a Class type and hasBeanClass() return false.

    I think I have a fix in this branch

  8. jhoeller commented on Jul 31, 2019

    @jhoeller
    Contributor

    Resolving a FactoryBean class along the lines of that branch looks ok to me...

  9. added 2 commits that reference this issue on Sep 17, 2026
    a0e4625
    89d150d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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