Skip to content

Flexible constructor resolution in AutowireCapableBeanFactory.createBean(Class) #29855

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

Closed
jhoeller opened this issue Jan 19, 2023 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

jhoeller commented Jan 19, 2023

In the course of addressing #29823, it turns out that AutowireCapableBeanFactory.createBean(Class) could apply AUTOWIRE_CONSTRUCTOR by default, kicking in when no AutowiredAnnotationBeanPostProcessor or the like specifically determines constructors to consider. This extends the semantics of the createBean(Class) method itself to flexibly select a constructor rather than potentially insist on a no-arg constructor.

Note that with AutowiredAnnotationBeanPostProcessor present, even a non-annotated constructor with arguments would be selected if no default constructor is declared (due to AABPP's general algorithm). This effectively contradicts the AbstractAutowireCapableBeanFactory default behavior, it was just not noticeable since AutowiredAnnotationBeanPostProcessor used to be present in all common application context setups.

With this aligned, all existing calls of createBean(beanClass, AUTOWIRE_CONSTRUCTOR, false) in various Spring integration points can be replaced with createBean(Class) then. This also serves as a preparation for deprecating the autowireMode-based AutowireCapableBeanFactory methods eventually.

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

1 participant