diff --git a/framework-docs/modules/ROOT/pages/core/aot.adoc b/framework-docs/modules/ROOT/pages/core/aot.adoc index 7914611b002f..cdd7cf71b4fc 100644 --- a/framework-docs/modules/ROOT/pages/core/aot.adoc +++ b/framework-docs/modules/ROOT/pages/core/aot.adoc @@ -36,7 +36,7 @@ NOTE: At the moment, AOT is focused on allowing Spring applications to be deploy We intend to support more JVM-based use cases in future generations. [[aot.basics]] -== AOT engine overview +== AOT Engine Overview The entry point of the AOT engine for processing an `ApplicationContext` is `ApplicationContextAotGenerator`. It takes care of the following steps, based on a `GenericApplicationContext` that represents the application to optimize and a {spring-framework-api}/aot/generate/GenerationContext.html[`GenerationContext`]: @@ -225,7 +225,7 @@ When a `datasource` instance is required, a `BeanInstanceSupplier` is called. This supplier invokes the `dataSource()` method on the `dataSourceConfiguration` bean. [[aot.running]] -== Running with AOT optimizations +== Running with AOT Optimizations AOT is a mandatory step to transform a Spring application to a native executable, so it is automatically enabled when running in this mode. It is possible to use those optimizations @@ -244,7 +244,7 @@ However, keep in mind that some optimizations are made at build time based on a This section lists the best practices that make sure your application is ready for AOT. [[aot.bestpractices.bean-registration]] -=== Programmatic bean registration +=== Programmatic Bean Registration The AOT engine takes care of the `@Configuration` model and any callback that might be invoked as part of processing your configuration. If you need to register additional @@ -266,7 +266,7 @@ notion of a classpath. For cases like this, it is crucial that the scanning happ build time. [[aot.bestpractices.bean-type]] -=== Expose The Most Precise Bean Type +=== Expose the Most Precise Bean Type While your application may interact with an interface that a bean implements, it is still very important to declare the most precise type. The AOT engine performs additional checks on the bean type, such as detecting the presence of `@Autowired` members or lifecycle callback methods. @@ -326,21 +326,21 @@ However, this is not a best practice and flagging the preferred constructor with 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. -[[aot.bestpractices.comlext-data-structure]] -=== Avoid Complex Data Structure for Constructor Parameters and Properties +[[aot.bestpractices.complex-data-structures]] +=== Avoid Complex Data Structures for Constructor Parameters and Properties When crafting a `RootBeanDefinition` programmatically, you are not constrained in terms of types that you can use. For instance, you may have a custom `record` with several properties that your bean takes as a constructor argument. While this works fine with the regular runtime, AOT does not know how to generate the code of your custom data structure. A good rule of thumb is to keep in mind that bean definitions are an abstraction on top of several models. -Rather than using such structure, decomposing to simple types or referring to a bean that is built as such is recommended. +Rather than using such structures, decomposing to simple types or referring to a bean that is built as such is recommended. As a last resort, you can implement your own `org.springframework.aot.generate.ValueCodeGenerator$Delegate`. To use it, register its fully qualified name in `META-INF/spring/aot.factories` using the `Delegate` as the key. [[aot.bestpractices.custom-arguments]] -=== Avoid Creating Bean with Custom Arguments +=== Avoid Creating Beans with Custom Arguments Spring AOT detects what needs to be done to create a bean and translates that in generated code using an instance supplier. 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: