[JAVA] Spring Boot Hot Swapping settings

I recently got into Spring Boot and was looking into setting up Hot Swapping, but I had a hard time unexpectedly because some articles were a little out of date or lacking in settings, so I will summarize them here.

Environmental information

Setup steps

Check Build project automatically in Preferences.

image.png

Display the command search window with Shift + Command + A and executeRegistry ....

image.png

Check compiler.automake.allow.when.app.running.

image.png

Add the following settings in build.gradle.

bootRun {
    sourceResources sourceSets.main
}

Add the following to ʻapplication.properties` (if you are using Thymeleaf as your template engine):

spring.thymeleaf.cache = false

About reload movement

For example, making changes to the source in src / main / java / hello / GreetingController.java will reload the application. In my environment, I had to save the source file with Command + S in order for the reload to run.

...
Service shut down
2019-05-24 16:18:26.310  INFO 37740 --- [      Thread-33] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

The app has restarted
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

2019-05-24 16:18:31.397  INFO 37740 --- [  restartedMain] hello.Application                        : Starting Application on xxx.local with PID 37740 (/Users/takehiro/Documents/git/sprint-web-mvc/build/classes/java/main started by takehiro in /Users/user/Documents/git/sprint-web-mvc)
2019-05-24 16:18:31.398  INFO 37740 --- [  restartedMain] hello.Application                        : No active profile set, falling back to default profiles: default
2019-05-24 16:18:31.563  INFO 37740 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
...

Also, any changes to the static file src / main / resources / templates / greeting.html were reflected by reloading the browser. In this case, the application reload did not occur.

Live reload

By combining with the Live Reload extension of the browser, it will be possible to automatically reload without clicking the reload button of the browser each time. This is because Spring Boot Devtools has a built-in Live Reload server.

Extensions can be installed from here (http://livereload.com/extensions/).

Start the application first and display the screen in the browser. Click the LiveReload extension icon and make sure the status is LiveReload is connected, click to disable.

image.png

This will allow live reloading.

livereload.gif

reference

Recommended Posts

Spring Boot Hot Swapping settings
Spring Boot performance related settings
Spring Boot 2.x context path settings
Hot deploy with Spring Boot development
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Learning Spring Boot [Beginning]
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Download with Spring Boot
[Spring Boot] Environment construction (macOS)
Set context-param in Spring Boot
Try Spring Boot from 0 to 100.
Generate barcode with Spring Boot
Hello World with Spring Boot
Spring Boot on Microsoft Azure
How to change application.properties settings at boot time in Spring boot
Spring Boot tutorial task schedule
Spring 5 & Spring Boot 2 Hands-on preparation procedure
Get started with Spring boot
Hello World with Spring Boot!
[Spring Boot] Web application creation
spring boot port duplication problem
Run LIFF with Spring Boot
SNS login with Spring Boot
[Java] Thymeleaf Basic (Spring Boot)
Introduction to Spring Boot ① ~ DI ~
File upload with Spring Boot
Spring Boot starting with copy
Introduction to Spring Boot ② ~ AOP ~
CICS-Run Java application-(4) Spring Boot application
Spring Boot starting with Docker
Spring Boot + Springfox springfox-boot-starter 3.0.0 Use
Spring Boot DB related tips
Hello World with Spring Boot
Set cookies with Spring Boot
[Spring Boot] Easy paging recipe
Use Spring JDBC with Spring Boot
Docker × Spring Boot environment construction
Major changes in Spring Boot 1.5
Add module with Spring Boot
Getting Started with Spring Boot
NoHttpResponseException in Spring Boot + WireMock
[Spring Boot] Send an email
Spring Boot application that specifies DB connection settings with parameters
Introduction to Spring Boot Part 1
Spring Boot External setting priority