The Spring Blog announced the beta release of Spring Native on March 11, 2021. With Spring Native, you can integrate Spring applications with GraalVM into Native images. This will greatly improve application startup speed and reduce memory consumption.

I started to follow this blog to learn Spring Native: Spring Native in action (experience the SpringBoot application in 79 milliseconds)

However, there was a problem when building the image. According to the error message, there was an exception when downloading the package from Github. My experience tells me that I need to use a ladder at this time, but the package is too big, even if there is a ladder, it is difficult to download, and every time I build it, is there a way to speed up the download?

mvn clean -U -DskipTests spring-boot:build-image`
Copy the code

Find this q&A on Github (How to Download GraalVM Faster? There are big guy guidance on the construction of local download service, speed up the download method.

The method is as follows:

  1. Download the files required for the build to your local PC

Go to Release GraalVM Community Edition 21.1.0 and download four files:

Graalvm - ce - java11 - Linux - amd64-21.1.0. Tar. Gz graalvm - ce - java11 - Linux - amd64-21.1.0. Tar. Gz. Sha256 Native - image - installable - SVM - java11 - Linux - amd64-21.1.0. Jar Native - image - installable - SVM - java11 - Linux - amd64-21.1.0. Jar. Sha256Copy the code
  1. Starting the Http Service
python3 -m http.server
Copy the code

Access to the file download address, such as local I download address is: http://localhost:8000/Desktop/bindings/graalvm-ce-java11-linux-amd64-21.1.0.tar.gz

  1. Creating a Binding file

Next comes the most important step, the first step downloads 4 files in pairs, one of the files is sha256 checksum, now use the checksum as the file name, download path as the content. The file structure is as follows:

  1. Build the mirror

Since the maven plugin is fixed and cannot be modified, you need to build your own image using the Pack tool because you use the custom file service to download it. Download install Pack tool: pack execute build command:

Pack build webMVC /native --path target/ webMVC-1.0-snapshot. jar -e BP_NATIVE_IMAGE=true --volume "~/Desktop/bindings/graalvm:/platform/bindings/graalvm-deps"Copy the code

Parameter Description: WebMVC /native indicates the destination image name, which can be customized. The target/webmvc – 1.0 – the SNAPSHOT. Jar jar package path ~ / Desktop/bindings/graalvm: / platform/bindings/graalvm – deps in front of the colon is the path of the step 3, A fixed path followed by a colon cannot be changed. Note: it costs a lot to build, so make the docker configuration a bit higher, otherwise it will take a long time to build.

After the build is complete, you can see that docker has an additional image:

  1. run
docker run --rm -p 8080:8080 webmvc/native
Copy the code

Open a browser to access port 8080 and verify that the service is normal

You can see that the boot time is only 0.051 secondsThe direct startup time takes 1.857 secondsUsing the Docker stats command to check resource usage, you can see that less than 30M memory is used.