Skip to content

Commit eed1421

Browse files
committed
Document 'preferredConstructors' attribute escape hatch with AOT
See gh-30917
1 parent 4b7d1e3 commit eed1421

File tree

1 file changed

+7
-0
lines changed
  • framework-docs/modules/ROOT/pages/core

1 file changed

+7
-0
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/aot.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ Java::
256256

257257
If you are registering bean definitions programmatically, consider using `RootBeanBefinition` as it allows to specify a `ResolvableType` that handles generics.
258258

259+
[[aot.bestpractices.constructors]]
260+
=== Avoid Multiple Constructors
261+
The container is able to choose the most appropriate constructor to use based on several candidates.
262+
However, this is not a best practice and flagging the preferred constructor with `@Autowired` if necessary is preferred.
263+
264+
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.
265+
259266
[[aot.bestpractices.factory-bean]]
260267
=== FactoryBean
261268

0 commit comments

Comments
 (0)