How to use AppCDS with Spring Boot

Transcript 


In this video, I will show you how to use Application Class Data Sharing (AppCDS) with Spring Boot applications. AppCDS is a JVM feature that reads and parses a set of system classes and application classes, stores the data in an archive, and then reads the data from the archive upon startup, resulting in faster application startups. AppCDS is compatible with all applications and doesn’t require any code changes. Additionally, using AppCDS with Ahead-of-Time (AOT) processing, supported by Spring, further reduces startup time. We will explore how to use AppCDS and AOT processing on a local machine and in containers by dockerizing our application using Dockerfiles and Buildpacks.

For this tutorial, you will need a Spring Boot application. I’ll use the Spring Petclinic application, available on GitHub. You will also need Docker, so make sure the engine is up and running. Let's begin by creating an archive on a local machine. While no application code changes are required, enabling AOT processing in the Maven plugin configuration is necessary. Using Liberica JDK 23 and Spring Boot version 3.3 or later, we start by creating an executable JAR file using the maven clean package command. Running the application with a standard java -jar command initially takes almost four seconds to start.

Next, we create a CDS archive. Instead of using the executable JAR directly, the Spring team recommends unpacking it into an exploded JAR for production. After extracting it, we use options like -Dspring.aot.enabled and ArchiveClassesAtExit to create the archive. The Dsprint.context.exit=onRefresh option ensures the application exits automatically after startup. While some older classes may not be archived, most are included. Once the archive is created, running the application with the SharedArchiveFile option results in a startup time of less than two seconds, a 40% improvement.

To enable AppCDS in a container, we use a Dockerfile. The first stage employs the Liberica Runtime Container with LibericaJDK Lite and Alpaquita Linux to build the project. The second stage extracts the JAR into layers, optimizing image updates. Finally, the container is built using Liberica Runtime Container with a prepackaged AppCDS archive. Using options like -Dspring.aot.enabled and ArchiveClassesAtExit, we create the archive during the build process. The resulting container image is 287MB and starts in under three seconds.

We also demonstrate using Buildpacks to build a container image with AppCDS and AOT enabled. Buildpacks automatically create layered JARs and can be configured by adding environment variables like BP_SPRING_AOT_ENABLED and BP_JVM_CDS_ENABLED to the Maven plugin. While Buildpacks produce slightly larger images (e.g., 538MB), they simplify the process. Running the Buildpack-based container shows startup times of just over two seconds, confirming that AppCDS and AOT are working as expected.

In this video, we explored using AppCDS and AOT processing with Spring Boot applications. Don't forget to like, subscribe, and see you next time!

Summary

This tutorial demonstrates how to use Application Class Data Sharing (AppCDS) and Ahead-of-Time (AOT) processing with Spring Boot applications to reduce startup time by 40–50%. AppCDS creates an archive of parsed classes for faster loading, requiring no code changes, and works both locally and in containers. The tutorial covers building optimized Docker images using Dockerfiles or Buildpacks for efficient deployment and improved performance.

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Tags

Videos
card image
Apr 1, 2025
SBOMs & Java Security: Stay Compliant, Stay Protected!

A software bill of materials or SBOM is crucial for the modern development environment full of regulations, vulnerabilities, and hidden threats. In this video, we discuss what SBOMs are and how they help dealing with compliance audits and application security. We will explore the best open-source tools for generating SBOMs and provide a tutorial on creating an SBOM for your project and analyzing it for vulnerabilities.

Videos
Apr 1, 2025
SBOMs & Java Security: Stay Compliant, Stay Protected!

A software bill of materials or SBOM is crucial for the modern development environment full of regulations, vulnerabilities, and hidden threats. In this video, we discuss what SBOMs are and how they help dealing with compliance audits and application security. We will explore the best open-source tools for generating SBOMs and provide a tutorial on creating an SBOM for your project and analyzing it for vulnerabilities.

Further watching

Videos
card image
Jun 23, 2025
How to install Liberica Native Image Kit on Windows PC

Liberica Native Image Kit is a multilingual GraalVM-based set of utilities for creating native images. This guide will help you to install it on Windows PC.

Videos
card image
Apr 25, 2025
Java in 2025: Busting the Biggest Myths

Think Java is slow, outdated, or only for old-school enterprise apps? Think again. In this episode of Java Myth Busters, we debunk six common myths about Java, including performance issues, security concerns, and the myth that Java is dead. Discover how the JVM, Spring Boot, GraalVM, and modern JDK updates make Java one of the most powerful, scalable, and relevant languages in 2025.

Videos
card image
Apr 16, 2025
Spring Boot Buildpacks: Optimize, Secure, and Shrink Your Containers!

Buildpacks let you containerize Spring Boot apps without writing Dockerfiles, but the default settings aren’t always optimal. In this video, I’ll show you how to fine-tune buildpacks for faster startup, smaller images, and better security—so you get the best performance with minimal effort.