Skip to content

Commit 8c41421

Browse files
Update AOT documentation.
1 parent 65cde13 commit 8c41421

File tree

1 file changed

+89
-4
lines changed
  • src/main/antora/modules/ROOT/pages

1 file changed

+89
-4
lines changed

src/main/antora/modules/ROOT/pages/aot.adoc

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Classpath scanning is not possible in native image arrangements and so Spring ha
1616

1717
Ahead of time code generation is not limited to usage with GraalVM Native Image but also offers benefits when working with regular deployments and can help optimize startup performance on the jvm.
1818

19+
[NOTE]
20+
====
21+
With AOT optimizations some decisions (like database dialects for example) will be frozen at build time and get included as is in the application setup.
22+
====
23+
1924
If Ahead of Time compilation is enabled Spring Data can (depending on the actual Module in use) contribute several components during the AOT phase of your build.
2025

2126
* Bytecode for generated Type/Property Accessors
@@ -32,30 +37,110 @@ However, there users may fine tune the configuration with following options.
3237

3338
|`spring.aot.data.accessors.include`
3439
|Comma separated list of FQCN for which to contribute Bytecode for generated Type/Property Accessors.
35-
Ant-style include patterns matching package names (e.g. `com.acme.**`) or type names inclusion.
40+
Ant-style include patterns matching package names (e.g. `example.springdata.**`) or type names inclusion.
3641
Inclusion pattern matches are evaluated before exclusions for broad exclusion and selective inclusion.
3742

3843
|`spring.aot.data.accessors.exclude`
3944
|Comma separated list of FQCN for which to skip contribution of Bytecode for generated Type/Property Accessors.
40-
Ant-style exclude patterns matching package names (e.g. `com.acme.**`) or type names exclusion.
45+
Ant-style exclude patterns matching package names (e.g. `example.springdata.**`) or type names exclusion.
4146
Exclusion pattern matches are evaluated after inclusions for broad exclusion and selective inclusion.
4247

4348
|`spring.aot.repositories.enabled`
4449
|Boolean flag to control contribution of Source Code for Repository Interfaces
4550

4651
|`spring.aot.[module-name].repositories.enabled`
47-
|Boolean flag to control contribution of Source Code for Repository Interfaces for a certain module (eg. `jdbc`, `jpa`, `mongodb`, `cassandra`)
52+
|Boolean flag to control contribution of Source Code for Repository Interfaces for a certain module (eg. `cassandra`, `jdbc`, `jpa`, `mongodb`)
53+
54+
|`spring.aot.repositories.metadata.enabled`
55+
|Boolean flag to control contribution of JSON repository metadata containing query methods and actual query strings.
56+
Requires `spring.aot.repositories.enabled` to be enabled.
4857
|===
4958

5059
[[aot.repositories]]
5160
== Ahead of Time Repositories
5261

62+
[NOTE]
63+
====
64+
Ahead of Time repositories are only available for imperative (non reactive) repository interfaces of certain modules.
65+
The criteria identifying eligible query methods varies between the implementing modules.
66+
====
67+
5368
AOT Repositories are an extension to AOT processing by pre-generating eligible query method implementations.
5469
Query methods are opaque to developers regarding their underlying queries being executed in a query method call.
5570
AOT repositories contribute query method implementations based on derived, annotated, and named queries that are known at build-time.
5671
This optimization moves query method processing from runtime to build-time, which can lead to a significant performance improvement as query methods do not need to be analyzed reflectively upon each application start.
5772

58-
The resulting AOT repository fragment follows the naming scheme of `<Repository FQCN>Impl_AotRepository` and is placed in the same package as the repository interface.
73+
The resulting AOT repository fragment follows the naming scheme of `<Repository FQCN>Impl__AotRepository` and is placed in the same package as the repository interface.
74+
75+
[WARNING]
76+
====
77+
Consider AOT repository classes an internal optimization.
78+
Do not use them directly in your code as generation and implementation details may change in future releases.
79+
====
80+
81+
[[aot.repositories.json]]
82+
=== Repository Metadata
83+
84+
AOT processing introspects query methods and collects metadata about repository queries.
85+
Spring Data stores this metadata in JSON files that are named after the source repository within the same package.
86+
Repository JSON Metadata contains details about queries and fragments.
87+
An example for the following repository is shown below:
88+
89+
[tabs]
90+
======
91+
Metadata::
92+
+
93+
[source,json,role="primary"]
94+
----
95+
{
96+
"name": "example.springdata.UserRepository",
97+
"module": "JDBC",
98+
"type": "IMPERATIVE",
99+
"methods": [
100+
{
101+
"name": "findBy",
102+
"signature": "public abstract java.util.List<example.springdata.User> example.springdata.UserRepository.findBy()",
103+
"query": {
104+
"query": "SELECT * FROM User"
105+
}
106+
},
107+
{
108+
"name": "findByLastnameStartingWith",
109+
"signature": "public abstract org.springframework.data.domain.Page<example.springdata.User> example.springdata.UserRepository.findByLastnameStartingWith(java.lang.String,org.springframework.data.domain.Pageable)",
110+
"query": {
111+
"query": "SELECT * FROM User u WHERE lastname LIKE :lastname",
112+
"count-query": "SELECT COUNT(*) FROM User WHERE lastname LIKE :lastname"
113+
}
114+
},
115+
{
116+
"name": "findByEmailAddress",
117+
"signature": "public abstract example.springdata.User example.springdata.UserRepository.findByEmailAddress(java.lang.String)",
118+
"query": {
119+
"query": "select * from User where emailAddress = ?1"
120+
}
121+
},
122+
----
123+
124+
Repository::
125+
+
126+
[source,java,subs="attributes,specialchars",role="secondary"]
127+
----
128+
interface UserRepository extends CrudRepository<User, Integer> {
129+
130+
List<User> findBy();
131+
132+
Page<User> findByLastnameStartingWith(String lastname, Pageable page);
133+
134+
@Query("select * from User where emailAddress = ?1")
135+
User findByEmailAddress(String username);
136+
}
137+
----
138+
======
139+
140+
[NOTE]
141+
====
142+
Creating JSON metadata can be controlled via the `spring.aot.repositories.metadata.enabled` flag.
143+
====
59144

60145
[[aot.hints]]
61146
== Native Image Runtime Hints

0 commit comments

Comments
 (0)