The Spring Boot DevTools works very well in Eclipse and Spring Tool Suite, for automatic restart the application and auto refresh the browser whenever we make changes to code of a Spring Boot project.
However, in IntelliJ IDEA, it behaves slightly different and you need to do few extra steps to get it works properly.
Basically, to use Spring Boot Developer Tools, add the following dependency to your project’s Maven build file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency>
Then restart your Spring Boot application. In Eclipse or Spring Tool Suite, the automatic restart feature works immediately when you press Ctrl + S to save changes in the code.
However, in IntelliJ IDEA, you have to press Ctrl + F9 (Build Project) to trigger hot restart of the application. This is quite inconvenient but a hot-swap restart is much faster than a cold, full restart. You also notice that the browser does not refresh automatically.
To fix the problem and let IntelliJ IDEA triggers Spring Boot DevTools restarts the application really automatically, you need to do 2 extra steps.
First, enable Build project automatically in the Settings dialog. Click menu File Settings > Build, Execution, Deployment > Compiler as shown below:
Then open IntelliJ IDEA Registry. Press Shift + Ctrl + A and type registry:
Then in the Registry dialog, search for this key:
compiler.automake.allow.when.app.running
And check to enable it:
After done these two steps, you still have to deactivate IntelliJ IDEA window, e.g. switching to browser window (while testing) – for the Spring Boot application to restart. But it takes few seconds to happen – not as fast as in Eclipse/Spring Tool Suite.
Now, the auto restart and live reload (auto refresh browser) will work but not as good as in Eclipse or Spring Tool Suite. Hope in the future release, IntelliJ IDEA will improve it.
For visual steps, check out this video:
To learn more about the automatic restart and live reload features of Spring Boot DevTools, check the following posts: