Git: 2.49.0
Spring Boot: 3.5.5
Maven: 3.9+
Java: 24
Docker Desktop: Tested on 4.42.0
git clone https://github.com/deepaksorthiya/spring-boot-docker.git
cd spring-boot-docker
Build Project
./mvnw clean package -DskipTests
Remove directory application
if exists
rm -f -R application
Create Self Exploded Jar file
java -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination application
Run Self Exploded Jar file
java -jar .\application\spring-boot-docker-0.0.1-SNAPSHOT.jar
Started Application in 2.309 seconds (process running for 2.54)
./mvnw clean package -DskipTests
rm -f -R application
java -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination application
cd application
Training Run
java -XX:ArchiveClassesAtExit=application.jsa -D"spring.context.exit=onRefresh" -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Production Run
java -XX:SharedArchiveFile=application.jsa -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Started Application in 1.338 seconds (process running for 1.487)
Build Project With AOT mode
./mvnw -Pnative -DskipTests clean package
rm -f -R application
java -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination application
cd application
java -XX:ArchiveClassesAtExit=application.jsa -D"spring.context.exit=onRefresh" -D"spring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
java -XX:SharedArchiveFile=application.jsa -D"spring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Started Application in 0.92 seconds (process running for 1.066)
./mvnw -Pnative -DskipTests clean package
java -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination application
cd application
Execute the AOT cache training run
java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf -D"spring.aot.enabled=true" -D"spring.context.exit=onRefresh" -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Create the AOT cache
java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf -XX:AOTCache=app.aot -D"spring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Remove aotconf
as its unnecessary now
rm app.aotconf
Run AOT cache enabled
java -XX:AOTCache=app.aot -jar spring-boot-docker-0.0.1-SNAPSHOT.jar
Started Application in 0.817 seconds (process running for 0.988)
TBD
./mvnw clean -Pnative -DskipTests native:compile
./mvnw clean -Pnative spring-boot:build-image -DskipTests
Enable Spring AOT
and add
<BP_SPRING_AOT_ENABLED>true</BP_SPRING_AOT_ENABLED>
<BP_JVM_CDS_ENABLED>true</BP_JVM_CDS_ENABLED>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
<configuration>
<buildArgs>
<buildArg>--pgo</buildArg>
<buildArg>--gc=G1</buildArg>
<buildArg>-march=native</buildArg>
</buildArgs>
</configuration>
<env>
<!-- For native build -->
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<!-- For cds-aot build -->
<BP_SPRING_AOT_ENABLED>true</BP_SPRING_AOT_ENABLED>
<BP_JVM_CDS_ENABLED>true</BP_JVM_CDS_ENABLED>
</env>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_JVM_VERSION>24</BP_JVM_VERSION>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>-march=native</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
./mvnw clean spring-boot:build-image -DskipTests
OR for low image size
docker build --progress=plain -t deepaksorthiya/spring-boot-docker .
http://localhost:8080/
http://localhost:8080/server-info
http://localhost:8080/rest-client
http://localhost:8080/rest-client-error
http://localhost:8080/rest-server-error
http://localhost:8080/rest-client-delay
For further reference, please consider the following sections: