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.
Check Build project automatically
in Preferences.
Display the command search window with Shift + Command + A
and executeRegistry ...
.
Check compiler.automake.allow.when.app.running
.
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
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.
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
.
This will allow live reloading.
Recommended Posts