From eed14214b5cc6c6d739e04fc2123b16829dcfcf4 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 2 Aug 2023 16:40:13 +0200 Subject: [PATCH] Document 'preferredConstructors' attribute escape hatch with AOT See gh-30917 --- framework-docs/modules/ROOT/pages/core/aot.adoc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework-docs/modules/ROOT/pages/core/aot.adoc b/framework-docs/modules/ROOT/pages/core/aot.adoc index c7fce039272..7c2a5ddd092 100644 --- a/framework-docs/modules/ROOT/pages/core/aot.adoc +++ b/framework-docs/modules/ROOT/pages/core/aot.adoc @@ -256,6 +256,13 @@ Java:: If you are registering bean definitions programmatically, consider using `RootBeanBefinition` as it allows to specify a `ResolvableType` that handles generics. +[[aot.bestpractices.constructors]] +=== Avoid Multiple Constructors +The container is able to choose the most appropriate constructor to use based on several candidates. +However, this is not a best practice and flagging the preferred constructor with `@Autowired` if necessary is preferred. + +In case you are working on a code base that you can't modify, you can set the {api-spring-framework}/beans/factory/support/AbstractBeanDefinition.html#PREFERRED_CONSTRUCTORS_ATTRIBUTE[`preferredConstructors` attribute] on the related bean definition to indicate which constructor should be used. + [[aot.bestpractices.factory-bean]] === FactoryBean