Skip to content

Commit

Permalink
Document 'preferredConstructors' attribute escape hatch with AOT
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Aug 2, 2023
1 parent 4b7d1e3 commit eed1421
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions framework-docs/modules/ROOT/pages/core/aot.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eed1421

Please sign in to comment.