Hot Swapping in Spring Boot with Eclipse STS
In web application developing, hot swapping means that you can modify the source code and see the changes immediately, simply by reloading the page in the web browser, without rebuilding your project and have to restart the web server.
Some java web frameworks are ready with it, Play Framework is a good example, whereas using Spring Boot you have to do a little work.
In the following is shown how to obtain the hot swapping in a Spring Boot web application, using Eclipse STS and Thymeleaf as template engine.
1. Get spring-loaded to handle the java code
You can download spring-loaded 1.2.0 from here:
springloaded-1.2.0.RELEASE.jar
or check here for the last version:
https://github.com/spring-projects/spring-loaded
2. Add spring-loaded in Eclipse STS
Open Eclipse→ Right click on your project (your Spring Boot web app) → Run As →Spring Boot (launch the application at least one time as Spring Boot application).
Right click on your project→ Run As → Run Configurations… → Java Application → <project_name> → Arguments
Inside the text box VM Arguments append the spring-loaded option:
-javaagent:/<path-to>/springloaded-1.2.0.RELEASE.jar -noverify
where <path-to>
is the directory path where you have the spring-loaded jar file.
Then click Apply → Run.
Now you can try to modify some java code and see the changes reloading the web page.
3. Configure Thymeleaf
Open the application.properties
file and add the following line:
spring.thymeleaf.cache: false
This option disables the cache for thymeleaf, allowing you to modify thymeleaf pages and just reloading the page in the web browser to see the changes.
References
- http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-hotswapping
- https://www.youtube.com/watch?v=GTrNkhVnJBU
-
Martin Flower
-
Andrea
-
-
Kevin
-
zulkarnainshah