Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot swapping in Spring Boot

I've been doing a P.O.C with Spring Boot.

So far it's been going really good and promising, but there's one major drawback: I'm using an embedded server (i.e., packaging the web app in a .jar), so when developing I have to rebuild the jar and restart the server every time I change the CSS, HTML or JS files. There's not hot-swap. This really slows down the UI development.

I can think of several quick fixes, such as loading static resources off a different domain and serving it from a local nginx, and some more variations like this, but isn't there a built-in option of some sort when working with IntelliJ/Eclipse?

like image 585
Amnon Avatar asked Jan 28 '14 07:01

Amnon


People also ask

What is hot swap in Java?

Java IDEs and VMs support a feature called HotSwapping. It allows you to update the version of a class while the virtual machine is running, without needing to redeploy the webapp, restart, or otherwise interrupt your debugging session. It's a huge productivity boost if you're editing the body of a method.

How do I turn on hot deployment in spring boot?

Configure IDEA Click the currently running service, and then click Edit Configurations . Click on the program you want to configure, find On 'Update' action and On frame deactivation select Update classes and resources . Click OK to implement hot deployment. After the above configuration, after modifying the code.

What is LiveReload server in spring boot?

LiveReload: The Spring Boot DevTools module includes an embedded server called LiveReload. It allows the application to automictically trigger a browser refresh whenever we make changes in the resources. It is also known as auto-refresh. Note: We can disable the LiveReload by setting the property spring.

Which file execute first in spring boot?

For running the Spring Boot application, open the main application file, and run it as Java Application.


1 Answers

There are several options. Running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also hotswapping of Java class changes). Spring Boot devtools is a cheap way to get quite a big boost (just add it to your classpath). It works by restarting your application in a hot JVM when changes are detected. It also switches off things like thymeleaf caches while it is running, so you don't have to remember to do that yourself. You can use it with an external css/js compiler process if you are writing that code with higher level tools.

Spring Loaded is no longer recommended, but probably still in use. More sophisticated agent-based tools work much better if you need hot swapping with zero delay (e.g. JRebel).

See the docs for some up to date content

like image 88
Dave Syer Avatar answered Sep 24 '22 15:09

Dave Syer