You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: framework-docs/modules/ROOT/pages/core/aot.adoc
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -326,6 +326,19 @@ However, this is not a best practice and flagging the preferred constructor with
326
326
327
327
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.
328
328
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.
0 commit comments