Exploring Spring Native Beta 0.10 – 0.11
Tags: agilewebandappdevelo
Published: 2022-01-24 16:47:09

---
title: Exploring Spring Native Beta 0.10 – 0.11
published: true
date: 2021-12-21 10:36:13 UTC
tags: Agilewebandappdevelo
canonical_url: https://apiumhub.com/tech-blog-barcelona/spring-native-beta-010-011/
---

## General overview

This article is based on [**Spring Native 0.10.6 BETA**](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/) documentation.

![🔴](https://s.w.org/images/core/emoji/13.1.0/72x72/1f534.png) 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](https://docs.google.com/document/d/1UokyyJj-EGtY8YbBrWNFmxCFEm4zXO4G9AxDylMkoY8/edit#heading=h.6eljqib5ln0z) 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](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#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](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#troubleshooting) for the most common problems.  Also have a look at the [examples](https://github.com/spring-projects-experimental/spring-native/issues) & [issues](https://github.com/spring-projects-experimental/spring-native/issues) in the [github project](https://github.com/spring-projects-experimental/spring-native).

### 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](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#support-spring-boot) ones, some need special dependency management.
- Spring Cloud 2020.0.3 [starters](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#support-spring-cloud)
- Spring [data & others](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#support-spring-data) (Lombok, jdbc drivers, gprc, spring-kafka, …)

### Limitations

[https://www.graalvm.org/reference-manual/native-image/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](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#getting-started-buildpacks), and [with Native Build Tools](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#getting-started-native-build-tools) in the [Spring Native Documentation](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/).

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
```

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
```

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](https://lh3.googleusercontent.com/gAAzz9TpRzEPeyyaCLhuVUHeEBVfdC2lzg-1RGKMCztNIl94VI3ZBAjk3CtgcLGc3BgYlcetk75iSNlWdCZQcHuizCZrDJvilX5BkJJ8ERIngZbQ0myOYrB3KvAS1oPdrfK2LtID "Exploring Spring Native Beta 0.10 - 0.11 8")

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

![9tZxhzXVAMw8Pa8Ufyb5NMJ4UcwVfnC49 RrW26ERRA79TvFq1Zu3X2wKP4C SR02H H3Phl4QHqPp8XoRBBez81iPlsktqVd2r9potzz1](https://lh4.googleusercontent.com/_9tZxhzXVAMw8Pa8Ufyb5NMJ4UcwVfnC49-RrW26ERRA79TvFq1Zu3X2wKP4C_SR02H--_H3Phl4QHqPp8XoRBBez81iPlsktqVd2r9potzz1-Gv8q4R5Tt5O1lgyOxtFPBqGozK "Exploring Spring Native Beta 0.10 - 0.11 9")

After that, run it:

```
docker run --rm -p 8080:8080 rest-service-complete:0.0.1-SNAPSHOT
```

![zg7fLirN6mGqpTLWqmqqueUYUe9l R5QxiTgqqwsOnDibicmG3Cxy7rg7vgYLFzlq3mH2LNH6iYv1Q1uasRg0eu36N1Z3gpcpzMuQDqmMPi29KiqTv0a Rv0tpmVHahg jSI09bl](https://lh3.googleusercontent.com/zg7fLirN6mGqpTLWqmqqueUYUe9l_R5QxiTgqqwsOnDibicmG3Cxy7rg7vgYLFzlq3mH2LNH6iYv1Q1uasRg0eu36N1Z3gpcpzMuQDqmMPi29KiqTv0a_Rv0tpmVHahg-jSI09bl "Exploring Spring Native Beta 0.10 - 0.11 10")

And check it works: [http://localhost:8080/greeting](http://localhost:8080/greeting) should return

```
{"id":1,"content":"Hello, World!"}
```

### With Native Build Tools

We will use the same project but installing graalvm directly.  You’ll need [sdkman](https://sdkman.io/install) (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
```

Package native app:

```
mvn -Pnative -DskipTests package
```

![X0SS245xLo5h3J6lBh1TfLxSrKmG DrCljEt6ynbk0XhZtinMtq6StFmzp HifkWYaILG3Lo5TzMoCQRkNTGNLk2jfypQNl2sOpAV1WyZFNMpFbTv](https://lh5.googleusercontent.com/X0SS245xLo5h3J6lBh1TfLxSrKmG-DrCljEt6ynbk0XhZtinMtq6StFmzp_HifkWYaILG3Lo5TzMoCQRkNTGNLk2jfypQNl2sOpAV1WyZFNMpFbTv-OuuQKxdlXpN1JTrD0zJdC8 "Exploring Spring Native Beta 0.10 - 0.11 11")

Run it:

```
./target/spring-native-beta
```

![v3NZvxaKp57DraNuh8X nDSGrbMlPgg0ghq9ncQUazkRJ ZPIGhWPDPT2PVaWZF0q0 CH1k7KMu8JCrJ9QRcvApCtFFS0CcB xbNEpuCmpU4N1wJV2mj5X2ekJ6abtMS5ubUY Am](https://lh5.googleusercontent.com/v3NZvxaKp57DraNuh8X_nDSGrbMlPgg0ghq9ncQUazkRJ_ZPIGhWPDPT2PVaWZF0q0-CH1k7KMu8JCrJ9QRcvApCtFFS0CcB_xbNEpuCmpU4N1wJV2mj5X2ekJ6abtMS5ubUY-Am "Exploring Spring Native Beta 0.10 - 0.11 12")

And check it works: [http://localhost:8080/greeting](http://localhost:8080/greeting) should return

```
{"id":1,"content":"Hello, World!"}
```

## Spring Ahead of Time

We can [configure](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#spring-aot-configuration) 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](https://github.com/spring-projects-experimental/spring-native/tree/main/spring-native-configuration/src/main/java) project).

## Samples repository

In this [source repository examples](https://github.com/spring-projects-experimental/spring-native/tree/main/samples) 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](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-image-options-useful)”.  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](https://spring.io/blog/2021/12/09/new-aot-engine-brings-spring-native-to-the-next-level), the AOT engine has been changed, achieving:

- **better startup & memory improvements** , compatibility improvements, but less runtime flexibility. ![D8TX6iRCHR9gDC i5JVaR4r6591VEJXCqRwNIWfyvIQeps](https://lh6.googleusercontent.com/D8TX6iRCHR9gDC_i5JVaR4r6591VEJXCqRwNIWfyvIQeps-vTPHUy0StBjyEHlcj4UBfEcCNwfXBg_0U_0nLhnQbyR2CFZHA_MlNo2gLgymzkpoIYJp3961KF4eBQvFLBzoE7xZM "Exploring Spring Native Beta 0.10 - 0.11 13") ![NVJ2 yqbUx5XpMfbX5LcSh BN PmVYfEerP3oGTlTyk7 xOLV03rJu1dTopdRe6HeSEb7P4KeIQzDk L78KnKLdxtR6kYdlmTFhQ 66 88uHcbE7eyWGAyR4WI8no 1kGhdb4tvG](https://lh3.googleusercontent.com/NVJ2_yqbUx5XpMfbX5LcSh_BN-PmVYfEerP3oGTlTyk7-xOLV03rJu1dTopdRe6HeSEb7P4KeIQzDk-L78KnKLdxtR6kYdlmTFhQ-66_88uHcbE7eyWGAyR4WI8no-1kGhdb4tvG "Exploring Spring Native Beta 0.10 - 0.11 14")
- a **new** architecture plugin called “ **Extension points** ” that allows to programmatically configure AOT hints.
- **New** “ **AOT testing support** ” with Junit5 and [graalvm native-build-tools](https://github.com/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.