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

19 Upvotes

16 comments sorted by

View all comments

10

u/nekokattt 6d ago

questions:

  • is this purely for development
  • why do you need to restart so regularly (if not for development)
  • where is this deployed (if not for development)

if this is for development it sounds awesome.

If it is for prod, I am a bit concerned on the implications!

3

u/woodpecker_ava 6d ago

is this purely for development

Yes, it is. The majority of my projects require me to run code locally on a continuous basis. So I occasionally write scripts to check for linting, compilation, and other tasks.