DevTools restart uses development class loading and is normally absent from a packaged production archive; test suspected classloader defects under the final jar.
Spring Boot DevTools restart: reproduce classloader failures without it
Development has another loader
A receipt serializer is loaded from a project module while its dependency remains in a stable library loader. DevTools restart can replace application classes after a change without restarting the full JVM. That saves local feedback time, but static caches, custom reflection or serialization may expose classloader mismatches. A failure seen only after several IDE restarts should be reproduced once with restart disabled and once with the executable archive. Packaged classpath behavior] is the deployment reference.
Keep it out of deployment
Declare DevTools as a development-only dependency. Boot’s packaged archives exclude it by default, but inspect the final jar rather than assuming a build customization preserved that rule. Never force restart support on in production to fix a missing bean. That hides the real startup problem and adds a development tool to a sensitive environment. The condition report] can explain a missing bean directly.
Diagnose the actual class
Log both a class name and its defining classloader for the two objects involved in a cast failure; avoid logging payloads or credentials. Recreate the issue with a controlled classpath update, then restart disabled. If only DevTools fails, adjust local module loading or static cache ownership. If the packaged jar fails too, fix the underlying integration rather than a development restart setting.
Implementation contract
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
// For one local diagnostic run, disable restart as a JVM property:
// -Dspring.devtools.restart.enabled=falseCost and verification
Restart improves local iteration but holds two classloaders and can retain stale references in badly scoped static caches. Packaged production startup remains the release check.
Common Mistakes
- Do not force DevTools restart on in a production process.
- Do not blame every packaged startup error on the development loader.
- Do not rely on IDE restart as the only launch-mode test.
Read next
Spring Boot executable jar: load resources through the classpath, not a file path, Spring Boot condition report: locate the missing auto-configuration decision, Spring Boot configuration validation: reject an unusable relay before work starts, Spring Boot layered jar: keep dependency changes out of the application layer, Spring Boot auto-configuration: conditions and user-defined beans.
