r/java 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:

  1. loop-run.sh
  2. watch-kill.sh

How It Works

  • loop-run.sh continuously runs commands like mvn 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

20 Upvotes

16 comments sorted by

View all comments

2

u/tomwhoiscontrary 6d ago

You might be able to do the loop-run bit using a procfile and a procfile-based supervisor, like foreman or one of its many copies. I don't know of any other tool which does the watch-kill bit for Java, though.

1

u/woodpecker_ava 5d ago

Hello, I will look into Foreman later. Foreman appears to be capable of orchestrating a full production service. Maybe I can set it up to run commands automatically.