Skip to content

Commit 7102c33

Browse files
committed
Add section about using complex data structures with AOT
Closes gh-32273
1 parent 43409b0 commit 7102c33

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

+13
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.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.
341+
329342
[[aot.bestpractices.custom-arguments]]
330343
=== Avoid Creating Bean with Custom Arguments
331344

0 commit comments

Comments
 (0)