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: spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/system-requirements.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ You can also deploy Spring Boot applications to any servlet 5.0+ compatible cont
40
40
41
41
[[getting-started.system-requirements.graal]]
42
42
=== 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.
44
44
45
45
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.
46
46
You can also create native images using the the https://github.com/paketo-buildpacks/native-image[native-image Paketo buildpack].
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.
9
9
Nested configuration properties, however, *must* be annotated with `@NestedConfigurationProperty`, otherwise they won't be detected and will not be bindable.
10
10
11
11
include::code:MyProperties[]
12
12
13
13
The example above produces configuration properties for `my.properties.name` and `my.properties.nested.number`.
14
14
Without the `@NestedConfigurationProperty` annotation on the `nested` field, the `my.properties.nested.number` property would not be bindable in a native image.
15
15
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.
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.
23
23
This can be useful for a number of reasons, including:
24
24
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.
26
26
* 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.
27
27
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.
29
29
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.
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.
38
38
39
39
40
40
First, make sure that a Docker daemon is available (see https://docs.docker.com/installation/#installation[Get Docker] for more details).
41
41
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.
42
42
43
43
You also need to install `pack` by following https://buildpacks.io//docs/tools/pack/#install[the installation guide on buildpacks.io].
44
44
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:
46
46
47
47
[source,shell,indent=0,subs="verbatim"]
48
48
----
@@ -65,11 +65,11 @@ Once `pack` has finished, you can launch the application using `docker run`:
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/developing-your-first-application.adoc
== 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.
4
4
5
5
There are two main ways to build a Spring Boot native image application:
6
6
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.
8
8
* Using GraalVM Native Build Tools to generate a native executable.
9
9
10
10
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
32
32
The resulting image doesn't contain a JVM, instead the native image is compiled statically.
33
33
This leads to smaller images.
34
34
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.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/native-image/introducing-graalvm-native-images.adoc
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@
3
3
GraalVM Native Images provide a new way to deploy and run Java applications.
4
4
Compared to the Java Virtual Machine, native images can run with a smaller memory footprint and with much faster startup times.
5
5
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.
7
7
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.
9
9
This ahead-of-time processing involves statically analyzing your application code from its main entry point.
10
10
11
11
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
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.
37
37
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.
38
38
39
39
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:
49
49
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.
50
50
A Spring AOT processed application will typically generate:
@@ -65,32 +65,32 @@ A Spring AOT processed application will typically generate:
65
65
Spring applications are composed of Spring Beans.
66
66
Internally, Spring Framework uses two distinct concepts to manage beans.
67
67
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.
69
69
70
70
If we take a typical `@Configuration` class:
71
71
72
72
include::code:MyConfiguration[]
73
73
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.
77
77
78
78
When the `myBean` instance is required, Spring knows that it must invoke the `myBean()` method and use the result.
79
79
When running on the JVM, `@Configuration` class parsing happens when your application starts and `@Bean` methods are invoked using reflection.
80
80
81
81
When creating a native image, Spring operates in a different way.
82
82
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.
84
84
85
85
The Spring AOT process would convert the configuration class above to code like this:
86
86
87
87
include::code:MyConfiguration__BeanDefinitions[]
88
88
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.
90
90
91
91
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.
92
92
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`.
94
94
When a `myBean` instance is required, a `BeanInstanceSupplier` is called.
95
95
This supplier will invoke the `myBean()` method on the `myConfiguration` bean.
96
96
@@ -101,19 +101,19 @@ Spring AOT will generate code like this for all your bean definitions.
101
101
It will also generate code when bean post-processing is required (for example, to call `@Autowired` methods).
102
102
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.
103
103
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.
105
105
Generated source files can be found in `target/spring-aot/main/sources` when using Maven and `build/generated/aotSources` with Gradle.
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.
112
112
Hint files contain JSON data that describes how GraalVM should deal with things that it can't understand by directly inspecting the code.
113
113
114
114
For example, you might be using a Spring annotation on a private method.
115
115
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.
117
117
118
118
Hint files are generated under `META-INF/native-image` where they are automatically picked up by GraalVM.
0 commit comments