I ran into this problem while starting to prepare for Spring Boot 3.2 upgrade on one of the project's I'm currently working on. The problem is reproducible on simplest possible Spring Boot application based on 3.2.0-RC1 that doesn't use CRaC but runs on JDK with CRaC. Such setup results in the following error:
java.lang.NoClassDefFoundError: org/crac/management/CRaCMXBean
at org.springframework.boot.SpringApplication$CoordinatedRestoreAtCheckpointStartup.restoreTime(SpringApplication.java:1712) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at org.springframework.boot.SpringApplication$CoordinatedRestoreAtCheckpointStartup.startTime(SpringApplication.java:1717) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at org.springframework.boot.SpringApplication$Startup.started(SpringApplication.java:1673) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325) ~[spring-boot-3.2.0-RC1.jar:3.2.0-RC1]
at sample.SampleApplication.main(SampleApplication.java:23) ~[main/:na]
Caused by: java.lang.ClassNotFoundException: org.crac.management.CRaCMXBean
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
... 7 common frames omitted
I ran into this by building the project on GitHub Actions and using Zulu JDK 17, and in such environment the JDK variant with CRaC will be installed:
- name: Setup Java
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
distribution: zulu
java-version: 17
Run actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
with:
distribution: zulu
java-version: 17
java-package: jdk
check-latest: false
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
overwrite-settings: true
job-status: success
token: ***
Installed distributions
Trying to resolve the latest version from remote
Resolved latest version as 17.0.9+9
Trying to download...
Downloading Java 17.0.9+9 (Zulu) from https://cdn.azul.com/zulu/bin/zulu17.46.27-ca-crac-jdk17.0.9-linux_x64.tar.gz ...
Extracting Java archive...
/usr/bin/tar xz --warning=no-unknown-keyword -C /home/runner/work/_temp/773f714d-7c59-474f-a621-8c5b286e19a9 -f /home/runner/work/_temp/8a30c149-7c8d-4d3e-aa83-3b8ee6c3520e
Java 17.0.9+9 was downloaded
Setting Java 17.0.9+9 as the default
Creating toolchains.xml for JDK version 17 from zulu
Writing to /home/runner/.m2/toolchains.xml
Java configuration:
Distribution: zulu
Version: 17.0.9+9
Path: /opt/hostedtoolcache/Java_Zulu_jdk/17.0.9-9/x64
It seems that the cause for this is the following code in SpringApplication that makes an assumption that CRaC will be used (and that org.crac.management.CRaCMXBean is available on the classpath) simply on presence of jdk.crac:
https://github.com/spring-projects/spring-boot/blob/bf73131298027236471c91b79e51a2c2c047c5de/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java#L1686-L1689
Comment From: vpavic
I assume updated issue title should say without a dependency on org.crac:crac.
Comment From: wilkinsona
It should indeed. Thanks.