When you migrate from a dedicated container to use embedded-container-based solution like Spring Boot, you might find that automatic class re-loading is not readily available anymore. That is, you have to restart your application if you make a change on any Java classes.
Luckily, Spring team feels your pain and came up with Spring Boot Dev Tools. In essence, it’s a dependency which automatically restarts your Spring Boot Application when it detects any changes in your Classpath. The restart is much faster than the initial one as it intelligently finds out the only changed components to reload.
You can just add the below dependency in your pom.xml if you’re using Maven:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
However, if you use IntelliJ IDEA, you will realize that adding the above it’s just not enough. This is because unlike Eclipse, you need to explicitly tell IntelliJ IDEA to “Make The Project” for it to build to the target classpath.
You obviously don’t want to do this. So, the best way is to use Macros to invoke
"Make Project" upon a
"Save All" invocation (
To do that, follow the below simple steps:
Start Macro Recording
Stop Macro Recording- You can save the macro name as “Save & Make Project”
Copy- You can name the new keymap as “Spring Boot Application”
- Go down to expand the
macrosdirectory to find your newly macro (i.e. “Save & Make Project”).
- Double click to
Add Keyboard Shortcutand press
Sif you use Mac and
Sif you use Windows.
That’s it! Try to run your Spring Boot application and make a change in your API. Invoke
S and voila! You should see in your run console that Spring automatically restarts!
You’re welcome! :)
- Official Spring Boot Docs on Boot Dev Tools
- StackOverflow entry to set up make project automatically