Skip to content

Commit 4e1b8f9

Browse files
committed
Merge branch '6.1.x'
2 parents ca6d987 + cb5b9dc commit 4e1b8f9

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

framework-docs/modules/ROOT/pages/core/aot.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ However, this is not a best practice and flagging the preferred constructor with
326326

327327
In case you are working on a code base that you cannot modify, you can set the {spring-framework-api}/beans/factory/support/AbstractBeanDefinition.html#PREFERRED_CONSTRUCTORS_ATTRIBUTE[`preferredConstructors` attribute] on the related bean definition to indicate which constructor should be used.
328328

329+
[[aot.bestpractices.custom-arguments]]
330+
=== Avoid Creating Bean with Custom Arguments
331+
332+
Spring AOT detects what needs to be done to create a bean and translates that in generated code using an instance supplier.
333+
The container also supports creating a bean with {spring-framework-api}++/beans/factory/BeanFactory.html#getBean(java.lang.String,java.lang.Object...)++[custom arguments] that leads to several issues with AOT:
334+
335+
. The custom arguments require a dynamic introspection of a matching constructor or factory method.
336+
Those arguments can't be detected by AOT so the necessary reflection hints will have to be provided manually.
337+
. By-passing the instance supplier means that all the other optimizations after creation are skipped as well.
338+
For instance, autowiring on fields and methods will be skipped as they are handled in the instance supplier.
339+
340+
Rather than having prototype-scoped beans created with custom arguments, we recommend a manual factory pattern where a bean is responsible of the creation of the instance.
341+
329342
[[aot.bestpractices.factory-bean]]
330343
=== FactoryBean
331344

0 commit comments

Comments
 (0)