Skip to content

Commit bdedae2

Browse files
Polish native image documentation
See gh-32582
1 parent 010891a commit bdedae2

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/system-requirements.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ You can also deploy Spring Boot applications to any servlet 5.0+ compatible cont
4040

4141
[[getting-started.system-requirements.graal]]
4242
=== GraalVM Native Images
43-
Spring Boot applications can be <<native-image#native-image.introducing-graalvm-native-images,converted into a Native Image>> using using Graal {graal-version} or above.
43+
Spring Boot applications can be <<native-image#native-image.introducing-graalvm-native-images,converted into a Native Image>> using using GraalVM {graal-version} or above.
4444

4545
Images can be created using the https://github.com/graalvm/native-build-tools[native build tools] Gradle/Maven plugins or `native-image` tool provided by GraalVM.
4646
You can also create native images using the the https://github.com/paketo-buildpacks/native-image[native-image Paketo buildpack].

spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/advanced-topics.adoc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@
55

66
[[native-image.advanced.nested-configuration-properties]]
77
=== Nested Configuration Properties
8-
Reflection hints are automatically created for configuration properties by Spring's ahead-of-time engine.
8+
Reflection hints are automatically created for configuration properties by the Spring ahead-of-time engine.
99
Nested configuration properties, however, *must* be annotated with `@NestedConfigurationProperty`, otherwise they won't be detected and will not be bindable.
1010

1111
include::code:MyProperties[]
1212

1313
The example above produces configuration properties for `my.properties.name` and `my.properties.nested.number`.
1414
Without the `@NestedConfigurationProperty` annotation on the `nested` field, the `my.properties.nested.number` property would not be bindable in a native image.
1515

16-
NOTE: Please use public getters / setters, otherwise the properties won't be bindable.
16+
NOTE: Please use public getters and setters, otherwise the properties will not be bindable.
1717

1818

1919

2020
[[native-image.advanced.converting-executable-jars]]
21-
=== Converting a Spring Boot Executable JAR
22-
It is possible to convert a Spring Boot <<executable-jar#appendix.executable-jar, executable JAR>> into a native image as long at the jar contains the AOT generated assets.
21+
=== Converting a Spring Boot Executable Jar
22+
It is possible to convert a Spring Boot <<executable-jar#appendix.executable-jar, executable jar>> into a native image as long at the jar contains the AOT generated assets.
2323
This can be useful for a number of reasons, including:
2424

25-
* You can keeping your regular JVM pipeline and turn the JVM application into a native image on your CI/CD platform.
25+
* You can keep your regular JVM pipeline and turn the JVM application into a native image on your CI/CD platform.
2626
* As `native-image` https://github.com/oracle/graal/issues/407[does not support cross-compilation], you can keep an OS neutral deployment artifact which you convert later to different OS architectures.
2727

28-
You can convert a Spring Boot executable jar into a native image using buildpacks, or the `native-image` tool that is shipped with GraalVM.
28+
You can convert a Spring Boot executable jar into a native image using Cloud Native Buildpacks, or using the `native-image` tool that is shipped with GraalVM.
2929

30-
NOTE: Your executable JAR must include AOT generated assets such as generated classes and JSON hint files.
30+
NOTE: Your executable jar must include AOT generated assets such as generated classes and JSON hint files.
3131

3232

3333

3434
[[native-image.advanced.converting-executable-jars.buildpacks]]
3535
==== Using Buildpacks
36-
Spring Boot applications usually use Buildpacks via the Maven (`mvn spring-boot:build-image`), or Gradle (`gradle bootBuildImage`) integrations.
37-
You can, however, also use https://buildpacks.io//docs/tools/pack/[`pack`] to turn an AOT processed Spring Boot executable JAR into a native container image.
36+
Spring Boot applications usually use Cloud Native Buildpacks via the Maven (`mvn spring-boot:build-image`), or Gradle (`gradle bootBuildImage`) integrations.
37+
You can, however, also use https://buildpacks.io//docs/tools/pack/[`pack`] to turn an AOT processed Spring Boot executable jar into a native container image.
3838

3939

4040
First, make sure that a Docker daemon is available (see https://docs.docker.com/installation/#installation[Get Docker] for more details).
4141
https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user[Configure it to allow non-root user] if you are on Linux.
4242

4343
You also need to install `pack` by following https://buildpacks.io//docs/tools/pack/#install[the installation guide on buildpacks.io].
4444

45-
Assuming an AOT processed Spring Boot executable JAR built as `myproject-0.0.1-SNAPSHOT.jar` is in the `target` directory, run:
45+
Assuming an AOT processed Spring Boot executable jar built as `myproject-0.0.1-SNAPSHOT.jar` is in the `target` directory, run:
4646

4747
[source,shell,indent=0,subs="verbatim"]
4848
----
@@ -65,11 +65,11 @@ Once `pack` has finished, you can launch the application using `docker run`:
6565

6666
[[native-image.advanced.converting-executable-jars.native-image]]
6767
==== Using GraalVM native-image
68-
Another option to turn an AOT processed Spring Boot executable JAR into a native executable is to use the GraalVM `native-image` tool.
68+
Another option to turn an AOT processed Spring Boot executable jar into a native executable is to use the GraalVM `native-image` tool.
6969
For this to work, you'll need a GraalVM distribution on your machine.
7070
You can either download it manually on the {liberica-nik-download}[Liberica Native Image Kit page] or you can use a download manager like SDKMAN!.
7171

72-
Assuming an AOT processed Spring Boot executable JAR built as `myproject-0.0.1-SNAPSHOT.jar` is in the `target` directory, run:
72+
Assuming an AOT processed Spring Boot executable jar built as `myproject-0.0.1-SNAPSHOT.jar` is in the `target` directory, run:
7373

7474
[source,shell,indent=0,subs="verbatim"]
7575
----
@@ -86,7 +86,7 @@ NOTE: These commands work on Linux or MacOS machines, you will need to adapt the
8686
TIP: The `@META-INF/native-image/argfile` might not be packaged in your jar.
8787
It is only included when reachability metadata overrides are needed.
8888

89-
WARNING: The `native-image` `-cp` flag does not not accept wildcards.
89+
WARNING: The `native-image` `-cp` flag does not accept wildcards.
9090
You need to ensure that all jars are listed (the command above uses `find` and `tr` to do this).
9191

9292

spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/developing-your-first-application.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[[native-image.developing-your-first-application]]
22
== Developing Your First GraalVM Native Application
3-
Now that we have a good overview of GraalVM Native Images and how Spring's ahead-of-time engine works, we can look at how to actually create them.
3+
Now that we have a good overview of GraalVM Native Images and how the Spring ahead-of-time engine works, we can look at how to create an application.
44

55
There are two main ways to build a Spring Boot native image application:
66

7-
* Using Spring Boot Buildpacks support to generate a lightweight container containing a native executable.
7+
* Using Spring Boot support for Cloud Native Buildpacks to generate a lightweight container containing a native executable.
88
* Using GraalVM Native Build Tools to generate a native executable.
99

1010
TIP: The easiest way to start a new native Spring Boot project is to go to https://start.spring.io[start.spring.io], add the "`GraalVM Native Support`" dependency and generate the project.
@@ -32,8 +32,8 @@ This means you can just type a single command and quickly get a sensible image i
3232
The resulting image doesn't contain a JVM, instead the native image is compiled statically.
3333
This leads to smaller images.
3434

35-
NOTE: The builder used for the images is `builder:tiny`.
36-
It has small footprint and reduced surface attack, but you can also use `builder:base` or `builder:full` to have more tools available in the image for an improved developer experience.
35+
NOTE: The builder used for the images is `paketobuildpacks/builder:tiny`.
36+
It has small footprint and reduced surface attack, but you can also use `paketobuildpacks/builder:base` or `paketobuildpacks/builder:full` to have more tools available in the image if required.
3737

3838

3939

@@ -99,7 +99,7 @@ You can run the task using:
9999

100100
[[native-image.developing-your-first-application.buildpacks.running]]
101101
==== Running the example
102-
One you have run the appropriate build command, your a Docker image should be available.
102+
Once you have run the appropriate build command, a Docker image should be available.
103103
You can start your application using `docker run`:
104104

105105
[source,shell,indent=0,subs="verbatim"]
@@ -201,7 +201,7 @@ The native image executable can be found in the `target` directory.
201201

202202
[[native-image.developing-your-first-application.native-build-tools.gradle]]
203203
==== Using Gradle
204-
When the Native Build Tools Gradle plugin is applied to your project, the Spring Boot Gradle plugin will automatically trigger Spring's AOT engine.
204+
When the Native Build Tools Gradle plugin is applied to your project, the Spring Boot Gradle plugin will automatically trigger the Spring AOT engine.
205205
Task dependencies are automatically configured, so you can just run the standard `nativeCompile` task to generate a native image:
206206

207207
[source,shell,indent=0,subs="verbatim"]

spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/introducing-graalvm-native-images.adoc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
GraalVM Native Images provide a new way to deploy and run Java applications.
44
Compared to the Java Virtual Machine, native images can run with a smaller memory footprint and with much faster startup times.
55

6-
They are well suited to applications that are deployed using container images and are especially interesting when combined with "`Function as a service`" (FaaS) platforms.
6+
They are well suited to applications that are deployed using container images and are especially interesting when combined with "Function as a service" (FaaS) platforms.
77

8-
Unlike traditional applications written for the JVM, Graal Native Image applications require ahead-of-time processing in order to create an executable.
8+
Unlike traditional applications written for the JVM, GraalVM Native Image applications require ahead-of-time processing in order to create an executable.
99
This ahead-of-time processing involves statically analyzing your application code from its main entry point.
1010

1111
A GraalVM Native Image is a complete, platform-specific executable.
@@ -33,7 +33,7 @@ TIP: The {graal-native-image-docs}/Limitations/[Native Image Compatibility and O
3333

3434
[[native-image.introducing-graalvm-native-images.understanding-aot-processing]]
3535
=== Understanding Spring Ahead-of-Time Processing
36-
Typical Spring Boot applications are quite dynamic and a lot of configuration is performed at at runtime.
36+
Typical Spring Boot applications are quite dynamic and configuration is performed at runtime.
3737
In fact, the concept of Spring Boot auto-configuration depends heavily on reacting to the state of the runtime in order to configure things correctly.
3838

3939
Although it would be possible to tell GraalVM about these dynamic aspects of the application, doing so would undo most of the benefit of static analysis.
@@ -49,14 +49,14 @@ A closed-world assumption implies the following restrictions:
4949
When these restrictions are in place, it becomes possible for Spring to perform ahead-of-time processing during build-time and generate additional assets that GraalVM can use.
5050
A Spring AOT processed application will typically generate:
5151

52-
* Java source code.
53-
* Bytecode (for dynamic proxies etc).
52+
* Java source code
53+
* Bytecode (for dynamic proxies etc)
5454
* GraalVM JSON hint files:
55-
- Resource hints (`resource-config.json`).
56-
- Reflection hints (`reflect-config.json`).
57-
- Serialization hints (`serialization-config.json`).
58-
- Java Proxy Hints (`proxy-config.json`).
59-
- JNI Hints (`jni-config.json`).
55+
- Resource hints (`resource-config.json`)
56+
- Reflection hints (`reflect-config.json`)
57+
- Serialization hints (`serialization-config.json`)
58+
- Java Proxy Hints (`proxy-config.json`)
59+
- JNI Hints (`jni-config.json`)
6060

6161

6262

@@ -65,32 +65,32 @@ A Spring AOT processed application will typically generate:
6565
Spring applications are composed of Spring Beans.
6666
Internally, Spring Framework uses two distinct concepts to manage beans.
6767
There are bean instances, which are the actual instances that have been created and can be injected into other beans.
68-
There are also "`bean definitions`" which are used to define attributes of a bean and how its instance should be created.
68+
There are also bean definitions which are used to define attributes of a bean and how its instance should be created.
6969

7070
If we take a typical `@Configuration` class:
7171

7272
include::code:MyConfiguration[]
7373

74-
The "`bean definition`" is created by parsing the `@Configuration` class and finding the `@Bean` methods.
75-
In the above example, we're defining a `BeanDefinition` for a singleton bean named "`myBean`".
76-
We're also defining a `BeanDefinition` for the `MyConfiguration` class itself.
74+
The bean definition is created by parsing the `@Configuration` class and finding the `@Bean` methods.
75+
In the above example, we're defining a `BeanDefinition` for a singleton bean named `myBean`.
76+
We're also creating a `BeanDefinition` for the `MyConfiguration` class itself.
7777

7878
When the `myBean` instance is required, Spring knows that it must invoke the `myBean()` method and use the result.
7979
When running on the JVM, `@Configuration` class parsing happens when your application starts and `@Bean` methods are invoked using reflection.
8080

8181
When creating a native image, Spring operates in a different way.
8282
Rather than parsing `@Configuration` classes and generating bean definitions at runtime, it does it at build-time.
83-
Once the bean definitions have been discovered, they are processed and converted into source code that can be ultimately analyzed by the GraalVM compiler.
83+
Once the bean definitions have been discovered, they are processed and converted into source code that can be analyzed by the GraalVM compiler.
8484

8585
The Spring AOT process would convert the configuration class above to code like this:
8686

8787
include::code:MyConfiguration__BeanDefinitions[]
8888

89-
NOTE: The exact code generated may differ depending on the exact nature of your bean definitions.
89+
NOTE: The exact code generated may differ depending on the nature of your bean definitions.
9090

9191
You can see above that the generated code creates equivalent bean definitions to the `@Configuration` class, but in a direct way that can be understood by GraalVM.
9292

93-
There is a bean definition for the "`myConfiguration`" bean, and one for "`myBean`".
93+
There is a bean definition for the `myConfiguration` bean, and one for `myBean`.
9494
When a `myBean` instance is required, a `BeanInstanceSupplier` is called.
9595
This supplier will invoke the `myBean()` method on the `myConfiguration` bean.
9696

@@ -101,19 +101,19 @@ Spring AOT will generate code like this for all your bean definitions.
101101
It will also generate code when bean post-processing is required (for example, to call `@Autowired` methods).
102102
An `ApplicationContextInitializer` will also be generated which will be used by Spring Boot to initialize the `ApplicationContext` when an AOT processed application is actually run.
103103

104-
TIP: Although AOT generated source code can be verbose, it is quite readable and can be helpful to use when debugging an application.
104+
TIP: Although AOT generated source code can be verbose, it is quite readable and can be helpful when debugging an application.
105105
Generated source files can be found in `target/spring-aot/main/sources` when using Maven and `build/generated/aotSources` with Gradle.
106106

107107

108108

109109
[[native-image.introducing-graalvm-native-images.understanding-aot-processing.hint-file-generation]]
110110
==== Hint File Generation
111-
In addition to generating source files, Spring's AOT engine will also generate hint files that are used by GraalVM.
111+
In addition to generating source files, the Spring AOT engine will also generate hint files that are used by GraalVM.
112112
Hint files contain JSON data that describes how GraalVM should deal with things that it can't understand by directly inspecting the code.
113113

114114
For example, you might be using a Spring annotation on a private method.
115115
Spring will need to use reflection in order to invoke private methods, even on GraalVM.
116-
When such situations arise, Spring can write a "`reflection hint`" so that GraalVM knows that even though the private method isn't called directly, it still needs to be available in the native image.
116+
When such situations arise, Spring can write a reflection hint so that GraalVM knows that even though the private method isn't called directly, it still needs to be available in the native image.
117117

118118
Hint files are generated under `META-INF/native-image` where they are automatically picked up by GraalVM.
119119

0 commit comments

Comments
 (0)