Flexible constructor resolution in AutowireCapableBeanFactory.createBean(Class) #29855
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
In the course of addressing #29823, it turns out that
AutowireCapableBeanFactory.createBean(Class)
could applyAUTOWIRE_CONSTRUCTOR
by default, kicking in when noAutowiredAnnotationBeanPostProcessor
or the like specifically determines constructors to consider. This extends the semantics of thecreateBean(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 theAbstractAutowireCapableBeanFactory
default behavior, it was just not noticeable sinceAutowiredAnnotationBeanPostProcessor
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 withcreateBean(Class)
then. This also serves as a preparation for deprecating the autowireMode-basedAutowireCapableBeanFactory
methods eventually.The text was updated successfully, but these errors were encountered: