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

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

Closed
philwebb opened this issue Jul 27, 2019 · 2 comments
Closed

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

philwebb opened this issue Jul 27, 2019 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@philwebb
Copy link
Member

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.

@philwebb philwebb transferred this issue from spring-projects/spring-boot Jul 27, 2019
@philwebb philwebb added in: core Issues in core modules (aop, beans, core, context, expression) status: blocked An issue that's blocked on an external project change labels Jul 27, 2019
@jhoeller jhoeller 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 Aug 1, 2019
@philwebb philwebb removed the status: blocked An issue that's blocked on an external project change label Aug 10, 2019
@philwebb philwebb added this to the 5.2 RC2 milestone Aug 12, 2019
@jhoeller jhoeller added the type: enhancement A general enhancement label Aug 12, 2019
@jhoeller jhoeller changed the title Provide a way to obtain bean types before without initializing them Provide a way to predict bean types without initializing them Sep 2, 2019
@jhoeller jhoeller changed the title Provide a way to predict bean types without initializing them Provide a way to predict bean types without initializing FactoryBeans Sep 2, 2019
@jhoeller
Copy link
Contributor

jhoeller commented Sep 2, 2019

@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?

@philwebb
Copy link
Member Author

philwebb commented Sep 2, 2019

@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.

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants