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
Jun 18, 2025
Java DTO Guide: Fix Your API Design with One Simple Pattern

This tutorial shows how to use the Data Transfer Object (DTO) pattern to transfer data between application layers. We use Java records to reduce boilerplate code and the MapStruct library that simplifies Java bean mapping.

Videos
card image
Jun 13, 2025
Downgraded Java to JDK 1.1 After 30 Years… (part 1)

How should we change Java 23 code for it to run on Java 1.1? We go line by line, removing modern features like records, sealed classes, switch expressions, var, and more. Each step reveals what breaks, how to rewrite it, and what you lose in the process. If you've ever wondered how far modern Java has drifted from its roots - this is your deep dive into that gap. This is Part 1 of the Java Downgrade Challenge, where we descend version by version until we reach Java 8. Subscribe to our channel to find out how we go even deeper - all the way down to Java 1.1. Stay tuned!

Further watching

Videos
card image
Jul 15, 2025
Java Downgrade Challenge: From JDK 8 to 1.1 (Part 2)

In Part 2 of the Java Downgrade Challenge, we continue our journey — now from Java 8 all the way to Java 1.1. No streams, no lambdas, no generics, no collections — and at one point, we even boot up Windows 98. If you thought Part 1 was painful, this one unwinds Java history line by line. By the end, the familiar Java from today will be almost gone.

Videos
card image
Jun 27, 2025
5x Smaller Java Docker Images — 2025 Optimization Guide

In this video, I’ll show you how to make your Java Docker images 5 TIMES SMALLER. You’ll see the full process, from a heavy 587MB container to a lean 116MB image, ready for production.

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.