A Spring Boot application compiled to a native executable using GraalVM Native Image and Spring AOT (Ahead-of-Time compilation). This demonstrates the dramatic performance improvements achievable with native compilation.
This project showcases:
- Spring Boot 3.5.7 with native image support
- Apache Camel and Camel Spring Boot 4.14.2 integration
- Native executable generation with GraalVM
- Java 21 or later
- Maven 3.x
- GraalVM (for native compilation)
Configure the required environment variables for GraalVM:
export GRAAL_21_HOME=/Library/Java/JavaVirtualMachines/graalvm-21.jdk/Contents/Home/
export GRAAL_HOME=${GRAAL_21_HOME}
export JAVA_HOME=${GRAAL_21_HOME}
export PATH=$JAVA_HOME/bin:$PATHNote: Adjust the GRAAL_21_HOME path to match your GraalVM installation location.
Build the Spring application and invoke the AOT engine:
mvn clean compile spring-boot:process-aot packageThis command:
- Compiles the application
- Processes the application with Spring's AOT engine
- Packages the application for native compilation
For more details, see the Spring Boot AOT Maven Plugin documentation.
Generate reflection metadata for GraalVM native image compilation. This step uses the native-image-agent to capture runtime reflection usage and create configuration files.
You can use the included generate.sh script or run the command directly:
java -Dspring.aot.enabled=true \
-agentlib:native-image-agent=config-merge-dir=./src/main/resources/META-INF/native-image/ \
-jar target/my-camel-springboot-app-1.0.0-SNAPSHOT.jarThis command:
- Runs the application with the native-image-agent attached
- Captures reflection, JNI, and resource usage during runtime
- Generates JSON configuration files in
src/main/resources/META-INF/native-image/ - Merges with existing configuration if present
For more details, see:
Compile the application to a native executable:
mvn native:compile-no-forkUpon successful completion, you will have a native executable at:
target/my-camel-springboot-app
Execute the native binary:
./target/my-camel-springboot-appStartup Time: 0.088 seconds (88 milliseconds)
The native executable demonstrates exceptional startup performance compared to traditional JVM-based Spring Boot applications.
Sample Startup Output
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.5.7)
2025-11-04T17:03:49.899-05:00 INFO 11247 --- [ main] com.example.MySpringBootApplication : Starting AOT-processed MySpringBootApplication using Java 21.0.9
2025-11-04T17:03:49.971-05:00 INFO 11247 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2025-11-04T17:03:49.979-05:00 INFO 11247 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.14.2 (MyCamel) started in 7ms
2025-11-04T17:03:49.979-05:00 INFO 11247 --- [ main] com.example.MySpringBootApplication : Started MySpringBootApplication in 0.088 seconds (process running for 0.095)
Hello World
Hello World
Build a native image as a container using Cloud Native Buildpacks:
mvn -Pnative spring-boot:build-imageThis approach uses Paketo buildpacks to create a containerized native image without requiring a local GraalVM installation.
Configuration Options:
You can customize the build with various options for memory allocation, JVM version, and JMX settings. See the Paketo Bellsoft Liberica Buildpack documentation for more details.
If using Podman, you may hit build errors around permissions which can be solved by setting the docker host in the spring-boot-maven-plugin configuration or recreating your podman machine. See #24405 for details.
Important: Building native images is memory-intensive. Ensure your Docker or Podman engine has sufficient memory allocated (recommended: 8GB or more).
Running the Container:
docker run -p 8080:8080 --rm docker.io/library/my-camel-springboot-app:1.0.0-SNAPSHOT