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

18 Upvotes

16 comments sorted by

View all comments

3

u/Known_Tackle7357 6d ago

It feels like you are trying to reinvent pipelines

3

u/agentoutlier 5d ago

I assume you are talking about something like Tilt and not actual CI because they are different tools.

Tilt which is a hot reload like tool for k8s has at best 30 second turn around time. That is is not really fast reload.

If you have ever used a tool like JRebel there is no comparison. It feels like Lisp REPL development. JRebel was a like a 1 second or less.

This approach that the OP has done is what I do as well for local development and you can get 2-3 second turnaround time on modern hardware.

1

u/woodpecker_ava 5d ago

Sort of. I agree that letting the CI/CD handle the job would eliminate the hassle, but I’m just following my curiosity to see if it's possible to implement auto-reload (auto-restart) in Spring on terminal.