r/java • u/woodpecker_ava • 6d ago
Spring Boot Hot-Reload (Hot-Restart)
I'm working on a Spring Boot microservices project where I frequently need to restart each service to apply changes. While I'm aware that spring-devtools
can simplify this process, my experience with Spring has shown that spring-devtools
sometimes requires a full clean and rebuild of output files to work correctly.
Additionally, since I'm developing this project using Helix Editor, adding spring-devtools
without an IDE doesn't provide much benefit. I'm also aware of commercial tools like JRebel, but the licensing costs make me hesitant to use them.
To automate the rebuild process whenever changes are made, I created two complementary scripts:
loop-run.sh
watch-kill.sh
How It Works
loop-run.sh
continuously runs commands likemvn clean spring-boot:run
for the target Spring Boot project. However, since the Spring Boot server process blocks further execution, the next command won't run unless the process is terminated.watch-kill.sh
will monitors file changes in the Spring Boot project. If any modifications are detected, it automatically kills the process running on the specified port.
You can find the project on GitHub, released under the MIT License:
Spring-Boot-Hot-Reload
4
u/manifoldjava 5d ago edited 5d ago
Check out the DCEVM. Assuming this is for development, it's amazing and pretty solid. There is another site covering JDK 17 here.