Skip to content

deepaksorthiya/spring-boot-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Docker Starter Project

JVM Maven Build GraalVM Maven Build Docker Spring Boot

Getting Started

Requirements:

Git: 2.49.0
Spring Boot: 3.5.5
Maven: 3.9+
Java: 24
Docker Desktop: Tested on 4.42.0

Clone this repository:

git clone https://github.com/deepaksorthiya/spring-boot-docker.git
cd spring-boot-docker

Running Application In Different Mode and Startup Performance

1. Exploded Jar

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)

2. CDS Mode With Exploded Jar

./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)

3. Spring-AOT + CDS

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)

4. JDK 24 AOT-Cache(Successor of CDS) + Spring-AOT

./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)

5. Project Leyden

TBD

YouTube Video

6. GraalVM Native Mode

GraalVM Native Images

./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>

Image Optimization

<configuration>
    <buildArgs>
        <buildArg>--pgo</buildArg>
        <buildArg>--gc=G1</buildArg>
        <buildArg>-march=native</buildArg>
    </buildArgs>
</configuration>

Buildpacks

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

Build Docker Image(docker should be running):

./mvnw clean spring-boot:build-image -DskipTests

OR for low image size

docker build --progress=plain -t deepaksorthiya/spring-boot-docker .

Rest APIs

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

Reference Documentation

For further reference, please consider the following sections:

About

Publish Docker Image to DockerHub and rest client examples

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •