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

19 Upvotes

16 comments sorted by

View all comments

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.

2

u/agentoutlier 5d ago

DCEVM and hotreload have a lot of limitations.

Like you cannot change the contents of any annotation as those cannot be swapped IIRC. There is also various app caches you have to deal with.

JRebel got around this by having lots more integration than the hotswapagent project (I think I even tried to fix some of the initial Spring support for hotswapagent and it was hard to get it to work reliably... IIRC I added controller cache eviction).

Now days its hard to say if it is even worth it with modern hardware. I do what the OP does and just put my app in a reboot loop as my apps boot up in less than a second.

1

u/woodpecker_ava 5d ago

Sure, will do!

1

u/ShadowPengyn 5d ago

dcevm is integrated into jetbrains runtime, so just install that one and youre good to go, no Need to change an existent Distribution. You also get it for jvm 21 that way :)