DEV Community

Apiumhub
Apiumhub

Posted on • Originally published at apiumhub.com on

Exploring Spring Native Beta 0.10 – 0.11

General overview

This article is based on Spring Native 0.10.6 BETA documentation.

🔴 but version 0.11 has just been released and it’s highly recommendable to use v0.11 for many improvements with a new AheadOfTime (AOT) engine. Check the Version 0.11 section in this article.

So let’s take a look at the benefits and limitations of this first version. I recommend checking out the full overview section in the official documentation.

Always keep in mind that we are working with a BETA version that has some limitations & incompatibilities. In the official documentation we can find a troubleshooting guide for the most common problems. Also have a look at the examples & issues in the github project.

Pre-requisites

  • 16GB RAM (in the pc compiling to native)
  • Spring Boot 2.5.6
  • Java 8, Java 11, and Kotlin 1.5+
  • GraalVM version 21.2.0

Spring-boot compatibility

  • Spring-boot starters: Check out all supported ones, some need special dependency management.
  • Spring Cloud 2020.0.3 starters
  • Spring data & others (Lombok, jdbc drivers, gprc, spring-kafka, …)

Limitations

https://www.graalvm.org/reference-manual/native-image/Limitations/

Spring Native with BuildPacks or Native Build Tools

In this article we’ll follow the, both, Getting Started Guides with Buildpacks, and with Native Build Tools in the Spring Native Documentation.

You can clone the project for this article build it if you like.

git clone https://github.com/davidgfolchApium/spring-native-beta.git
cd spring-native-beta
Enter fullscreen mode Exit fullscreen mode

It’s the same rest-api example used in the Spring Native documentation but with all modifications needed for both builds.

With Buildpacks

It allows us to build & run with a single command line

mvn spring-boot:build-image
Enter fullscreen mode Exit fullscreen mode

It worked out-of-the-box, as usual in the Spring ecosystem.

It took 30 minutes to finish that process the first time.

You can go for a break…

gAAzz9TpRzEPeyyaCLhuVUHeEBVfdC2lzg 1RGKMCztNIl94VI3ZBAjk3CtgcLGc3BgYlcetk75iSNlWdCZQcHuizCZrDJvilX5BkJJ8ERIngZbQ0myOYrB3KvAS1oPdrfK2LtID

Note that next builds should go kicker because we already have some buildpacks/docker things done.

9tZxhzXVAMw8Pa8Ufyb5NMJ4UcwVfnC49 RrW26ERRA79TvFq1Zu3X2wKP4C SR02H H3Phl4QHqPp8XoRBBez81iPlsktqVd2r9potzz1

After that, run it:

docker run --rm -p 8080:8080 rest-service-complete:0.0.1-SNAPSHOT
Enter fullscreen mode Exit fullscreen mode

zg7fLirN6mGqpTLWqmqqueUYUe9l R5QxiTgqqwsOnDibicmG3Cxy7rg7vgYLFzlq3mH2LNH6iYv1Q1uasRg0eu36N1Z3gpcpzMuQDqmMPi29KiqTv0a Rv0tpmVHahg jSI09bl

And check it works: http://localhost:8080/greeting should return

{"id":1,"content":"Hello, World!"}
Enter fullscreen mode Exit fullscreen mode

With Native Build Tools

We will use the same project but installing graalvm directly. You’ll need sdkman (recommended option) to install graalvm, and the native-extensions to the jdk.

sdk install java 21.2.0.r8-grl
sdk use java 21.2.0.r8-grl
gu install native-image
Enter fullscreen mode Exit fullscreen mode

Package native app:

mvn -Pnative -DskipTests package
Enter fullscreen mode Exit fullscreen mode

X0SS245xLo5h3J6lBh1TfLxSrKmG DrCljEt6ynbk0XhZtinMtq6StFmzp HifkWYaILG3Lo5TzMoCQRkNTGNLk2jfypQNl2sOpAV1WyZFNMpFbTv

Run it:

./target/spring-native-beta
Enter fullscreen mode Exit fullscreen mode

v3NZvxaKp57DraNuh8X nDSGrbMlPgg0ghq9ncQUazkRJ ZPIGhWPDPT2PVaWZF0q0 CH1k7KMu8JCrJ9QRcvApCtFFS0CcB xbNEpuCmpU4N1wJV2mj5X2ekJ6abtMS5ubUY Am

And check it works: http://localhost:8080/greeting should return

{"id":1,"content":"Hello, World!"}
Enter fullscreen mode Exit fullscreen mode

Spring Ahead of Time

We can configure some Spring AOT options to reduce foot-print, some are already disabled/enabled by default.

Native hints

We must use native hints to workaround some problems with:

  • Libraries not supported by Spring Native
  • Define any reflection needed by your app or any library (as Jackson)

Spring native AOT plugin will generate all *.properties & *.json configuration files needed in META-INF/native-image.

This specific configuration for our application could be set as properties files or with annotations (see spring-native-configuration project).

Samples repository

In this source repository examples we can check “the state of the art”, of several aspects, any Spring native application could need (build tools, agents, libraries, spring modules, etc).

The Pet Clinic web app integrates some of them.

Native image options

Some GraalVM options are defaulted by Spring, and some are called “Useful options”. And among these ones I will remark the –enable-https we need to specify if we have to serve through this protocol.

Tracing agent

It seems to be a “great” tool that will help generate all Native Hints needed for our new applications or libraries we could use.

Version 0.11

In this new version, the AOT engine has been changed, achieving:

  • better startup & memory improvements , compatibility improvements, but less runtime flexibility. D8TX6iRCHR9gDC i5JVaR4r6591VEJXCqRwNIWfyvIQeps NVJ2 yqbUx5XpMfbX5LcSh BN PmVYfEerP3oGTlTyk7 xOLV03rJu1dTopdRe6HeSEb7P4KeIQzDk L78KnKLdxtR6kYdlmTFhQ 66 88uHcbE7eyWGAyR4WI8no 1kGhdb4tvG
  • a new architecture plugin called “ Extension points ” that allows to programmatically configure AOT hints.
  • NewAOT testing support ” with Junit5 and graalvm native-build-tools (mockito not supported yet).
  • Others…

Spring is already planning “ Spring Boot 3 native support ” that will integrate this new version into the standards.

Top comments (0)