Allow preferred constructor to be defined at the BeanDefinition
level
#30917
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
theme: aot
An issue related to Ahead-of-time processing
type: enhancement
A general enhancement
Milestone
See #30900 for an example.
When crafting a
BeanDefinition
for a class with multiple constructors andAUTOWIRE_CONSTRUCTOR
mode, the regular runtime chooses the "most suitable" constructor based on the available beans in theBeanFactory
. Arguably this is a behavior that can be a bit surprising and can be expressed in a much better way usingOptional
orObjectProvider
for the constructor arguments that may or may not be present.AOT does not support this algorithm and we're not keen to change that as we're considering deprecating and removing the capability of choosing the constructor based on available dependencies. However, for existing use cases, users have no other choice than refactoring their code, such as adding
@Autowired
on the preferred constructor, or changing the signature to useOptional
orObjectProvider
. This issue is about offering an escape hatch, for instance adding an attribute at the bean definition level thatConstructorResolver
would use to pick up the preferred constructor.The text was updated successfully, but these errors were encountered: