Quick revision
The short answer
DevTools runs the application with two class loaders: a base class loader for the jars that do not change, such as Spring and Hibernate, and a restart class loader for our own classes. When a file on the classpath changes, DevTools throws away only the restart class loader and the application context, creates a new restart loader, and starts the context again, while the dependencies stay loaded and warmed up. It also applies development-friendly property defaults, and it switches itself off when the application runs as a packaged jar with java -jar.
What to remember
In this answer, we saw that DevTools speeds up restarts by splitting the classpath into a base class loader for dependency jars and a restart class loader for our own classes. On a change, it closes the context, discards only the restart loader and starts the context again in a fresh one, so dependencies stay loaded and warm. It also disables template caching and adds other development defaults, and it stays out of production by being excluded from repackaged jars and by switching itself off under java -jar.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
DevTools runs the application with two class loaders: a base class loader for the jars that do not change, such as Spring and Hibernate, and a restart class loader for our own classes. When a file on the classpath changes, DevTools throws away only the restart class loader and the application context, creates a new restart loader, and starts the context again, while the dependencies stay loaded and warmed up. It also applies development-friendly property defaults, and it switches itself off when the application runs as a packaged jar with java -jar.
Why this question is asked
Every Spring developer has waited for an application to restart after changing one line. DevTools exists to shorten that wait, and interviewers ask how it works because the answer reveals whether we understand class loaders, one of the less visible parts of the JVM. The same knowledge also explains strange errors DevTools can cause, which is a common follow-up question. In this answer, we will recap what a class loader is, see how DevTools splits the classpath, follow a restart step by step, see why it beats a cold start, and finish with the property defaults and the rules that keep DevTools out of production.
1A Quick Recap of Class Loaders
A class loader is the part of the JVM that finds a class's bytecode, usually in a jar or a folder, and turns it into a Class object the program can use. Class loaders form a hierarchy: each one has a parent, and it asks its parent first before loading a class itself.
Two facts matter here. First, a class loader never unloads a single class; classes go away only when their class loader and everything that references it become garbage. Second, a class is identified not just by its name but by its name together with the class loader that loaded it. So if we want to reload our classes without restarting the JVM, we need a class loader we can throw away.
2How DevTools Splits the Classpath
When we start the application from the IDE or with mvn spring-boot:run, DevTools steps in at the very start of SpringApplication.run. It looks at the classpath and splits it in two. Jars, which are third-party dependencies such as spring-core, hibernate-core and jackson-databind, go to the base class loader. Folders of compiled classes from our own project, such as target/classes, go to a new restart class loader, whose parent is the base loader.
Then DevTools starts our main method again on a new thread, called restartedMain, with the restart class loader as its context class loader. From that point on, our classes are loaded by the restart loader, and every Spring and library class by the base loader.
- Restart class loaderour classes from target/classes; replaced on each restart
- Base (application) class loaderall dependency jars; loaded once
- Platform and bootstrap loadersJDK classes
3 layers, from the top down. Step through them one at a time.
Only the top layer is thrown away when we change our code.
3What Happens on a Restart, Step by Step
DevTools watches the folders that the restart loader reads from. When we rebuild in the IDE, the changed .class files land in target/classes, and DevTools notices the classpath change. It waits a short quiet period so that one build triggers one restart, then begins.
It closes the current application context, which runs our shutdown callbacks and closes connection pools. It discards the restart class loader, so all our old classes become garbage. It creates a fresh restart class loader over the same folders and runs our main method again, which builds a new application context from the new classes.
Notice what is not touched: the base class loader. The thousands of classes from Spring, Hibernate, Jackson and the servlet container are still loaded, verified and in many cases already compiled to machine code by the JIT.
- Developer rebuildschanged .class files in target/classes
- File watcher sees the changewaits for a quiet period
- Close the application contextshutdown hooks, pools closed
- Discard the restart class loaderour old classes become garbage
- Create a new restart class loadersame folders, new bytecode
- Run main again on restartedMainnew context, same base loader
6 steps in order. Play them, or step through them one at a time.
Dependencies are never reloaded, which is where the time saving comes from.
4Why It Is Faster Than a Cold Start
A cold start pays for everything: starting the JVM, opening and indexing every jar, loading and verifying tens of thousands of classes, and running them slowly in the interpreter before the JIT compiles hot methods. For a typical service, most of those classes come from dependencies, not from our code.
A DevTools restart skips the JVM start and reuses all of the dependency classes. It still has to rebuild the Spring context, run our configuration and reconnect to the database, so it is not instant. As an example, a service that cold-starts in 9 seconds might restart in 2 or 3 seconds with DevTools. If the context itself is slow, because of heavy initialisation or a large component scan, DevTools cannot hide that cost.
5Development Defaults and Staying Out of Production
DevTools also changes some property defaults that are good in production but annoying in development. Template engines such as Thymeleaf and FreeMarker normally cache compiled templates; DevTools turns caching off, so a changed template shows on the next refresh. It also enables more detailed web logging and error details, and it starts a LiveReload server on port 35729 that tells a browser extension to refresh the page.
Finally, DevTools disables itself in a fully packaged application. If the application is launched with java -jar, or from a special class loader, DevTools considers it a production run and does nothing. On top of that, the Spring Boot Maven and Gradle plugins leave DevTools out of the repackaged jar by default when it is declared as optional in Maven or as developmentOnly in Gradle.
6Follow-up questions
How is DevTools restart different from hot swapping or JRebel?
Hot swapping, the JVM's built-in ability used by debuggers, replaces method bodies in loaded classes without a restart, but it cannot add fields or methods. Tools such as JRebel go further by reloading classes in place. DevTools takes a simpler route: it restarts the application context in fresh class loaders, which handles any code change but loses in-memory state on each restart.
Can we make DevTools ignore some changes?
Yes. spring.devtools.restart.exclude lists paths whose changes should not trigger a restart; static resources and templates are excluded by default because they can be served fresh without one. spring.devtools.restart.additional-paths watches extra folders, and setting spring.devtools.restart.enabled to false turns restart off while keeping the other DevTools features.
Why do we sometimes see two copies of the same class with DevTools?
Because a class's identity includes its class loader. If a library in the base loader holds on to an object created from our class by an older restart loader, or loads our class itself, the JVM sees two different classes with the same name. The usual fix is to move the jar into the restart loader with a restart.include entry in META-INF/spring-devtools.properties.
7Conclusion
In this answer, we saw that DevTools speeds up restarts by splitting the classpath into a base class loader for dependency jars and a restart class loader for our own classes. On a change, it closes the context, discards only the restart loader and starts the context again in a fresh one, so dependencies stay loaded and warm. It also disables template caching and adds other development defaults, and it stays out of production by being excluded from repackaged jars and by switching itself off under java -jar.
Open with
DevTools uses two class loaders. When the app starts from the IDE or spring-boot:run, it splits the classpath: dependency jars go into the base class loader, and our own compiled classes, target/classes, go into a restart class loader on top of it.
Then, if they want more
It then reruns main on a thread called restartedMain. When I rebuild and the classpath changes, DevTools closes the application context, throws away the restart class loader, creates a new one over the same folders and runs main again. The base loader is never touched, so Spring, Hibernate, Jackson and the rest stay loaded, verified and JIT-compiled.
That is why it is faster than a cold start: we skip starting the JVM and reloading tens of thousands of dependency classes, and only rebuild the context, so a nine-second start might become two or three seconds. It is not a hot swap, though; in-memory state is lost each time, and a slow context stays slow.
DevTools also sets development defaults, like turning off Thymeleaf template caching, and it runs LiveReload. And it keeps out of production on purpose: declared as optional or developmentOnly, the Boot plugins leave it out of the fat jar, and even if present it disables itself when the app is launched with java -jar.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does Spring Boot DevTools restart work, and why is it faster than a full JVM restart?": https://scrivio-interview-library.netlify.app/spring-boot/developer-experience/d3840eb116/