Skip to content

Provide a way to predict bean types without initializing FactoryBeans #23374

Closed

Description

@philwebb

See this comment for details.

I don't think we currently have a way to tell the predicted type of a bean without initializing it. It might be nice if we could either surface a getType(String name, boolean allowEagerInit) or perhaps add a callback based approach similar to the existing getBeanNames... methods:

<T> void doWithBeanNamesForType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit, BiConsumer<String, Class<T>> consumer);

We should wait until #23341 is merged before taking this on.

Activity

  1. added
    in: core
    status: blocked
    on Jul 27, 2019
  2. changed the title [-]Provide a way to obtain bean types before without initiazing them[/-] [+]Provide a way to obtain bean types before without initializing them[/+] on Aug 1, 2019
  3. removed
    status: blocked
    on Aug 10, 2019
  4. added this to the 5.2 RC2 milestone on Aug 12, 2019
  5. added
    type: enhancement
    on Aug 12, 2019
  6. changed the title [-]Provide a way to obtain bean types before without initializing them[/-] [+]Provide a way to predict bean types without initializing them[/+] on Sep 2, 2019
  7. changed the title [-]Provide a way to predict bean types without initializing them[/-] [+]Provide a way to predict bean types without initializing FactoryBeans[/+] on Sep 2, 2019
  8. jhoeller commented on Sep 2, 2019

    @jhoeller
    Contributor

    @philwebb Would you expect such a getType(String name, boolean allowFactoryBeanInit) method to be available on the BeanFactory interface, not just on the factory implementation hierarchy? And the flag would only affect the internal getTypeForFactoryBean call, I suppose?

  9. philwebb commented on Sep 2, 2019

    @philwebb
    MemberAuthor

    @jhoeller I haven't given too much thought, but I assumed on the interface next to BeanFactory.getType(String name) would be best. It probably doesn't matter too from our side since we can always cast.

    the flag would only affect the internal getTypeForFactoryBean call, I suppose?

    I think so. I think all the other areas of the current implementation don't cause initialization.

  10. added a commit that references this issue on Sep 17, 2026
    f26866e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions