Spring Native: What, Why and How?

Spring Native is in Beta

What are GraalVM Native Images?

What is Spring Native?

Advantages for native images

Building an example Native Image Disadvantages for native images

When do we best use Spring Native?

Building an example Native Image

First step Spring Initializr IntelliJ
Second step Spring Initializr IntelliJ
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>${spring-native.version}</version>
</dependency>
<plugin>
<
groupId>org.springframework.experimental</groupId>
<
artifactId>spring-aot-maven-plugin</artifactId>
<
version>${spring-native.version}</version>
<
executions>
<
execution>
<
id>test-generate</id>
<
goals>
<
goal>test-generate</goal>
</
goals>
</
execution>
<
execution>
<
id>generate</id>
<
goals>
<
goal>generate</goal>
</
goals>
</
execution>
</
executions>
</
plugin>
The result of the previous action
@Bean
public RouterFunction<ServerResponse> routes() {
return route()
.GET("/", request -> ServerResponse.ok().body(Mono.just("Hello everyone!\n"), String.class))
.build();
}
The result
$ mvn clean package
$ mvn spring-boot:build-image
$ docker images
Docker Images
$ docker run --name spring-native-example -p 8080:8080 spring-native-example:0.0.1-SNAPSHOT
Output of a native image
The result

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store