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
+13
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.comlext-data-structure]]
330
+
=== Avoid Complex Data Structure for Constructor Parameters and Properties
331
+
332
+
When crafting a `RootBeanDefinition` programmatically, you are not constrained in terms of types that you can use.
333
+
For instance, you may have a custom `record` with several properties that your bean takes as a constructor argument.
334
+
335
+
While this works fine with the regular runtime, AOT does not know how to generate the code of your custom data structure.
336
+
A good rule of thumb is to keep in mind that bean definitions are an abstraction on top of several models.
337
+
Rather than using such structure, decomposing to simple types or referring to a bean that is built as such is recommended.
338
+
339
+
As a last resort, you can implement your own `org.springframework.aot.generate.ValueCodeGenerator$Delegate`.
340
+
To use it, register its fully qualified name in `META-INF/spring/aot.factories` using the `Delegate` as the key.
0 commit comments