Hot deployment: Automatically launches applications when a program is found to be modified.
Spring boot provides developers with a module called Spring-boot-devtools to enable the Sring boot application to support hot deployment and increase developer productivity without having to manually restart the spring boot application.
The principle of Devtools
The underlying principle is to use two ClassLoader, one ClassLoader to load the classes that will not change (third-party jar packages), and another ClassLoader to load the changed classes, called Restart ClassLoader, so that when there is code change, The original restart ClassLoader will be discarded, re-create a restart ClassLoader, due to the need to load less analogy, so the faster restart time.
To add dependencies in Pom.xml:
<!--Hot Deployment - <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-devtools</Artifactid> <Optional>True</Optional> </Dependency>
Compile node Add:
<Build> <Plugins> <plugin> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-maven-plugin</Artifactid> <Configuration> <Fork>True</Fork> </Configuration> </plugin> </Plugins> </Build>
Description
Devtools can implement the hot deployment of the page, implement the hot deployment of the class file, and implement the hot deployment to the property file. That is, the devtools will listen to the changes in the Classpath file, but this way is a project restart, will empty the value of the session, that is, if a user login, the project restart to re-login.
By default,/meta-inf/maven,/meta-inf/resources,/resources,/static,/templates,/public file modifications under these folders do not cause the app to restart. But it reloads (a livereload server is embedded in the Devtools, and the browser refreshes when the resource changes).
Idea Settings
When we modify the Java class, idea is not automatically compiled by default, and Spring-boot-devtools is monitoring the file changes under Classpath to restart the application, so you need to set the idea's automatic compilation.
Other settings, default settings.
Command+shift+a Global Search
Find the compiler.automake.allow.when.app.running, tick on to turn on this feature
Restart the project at this time to take effect, change the code without restarting the project
Spring Boot Hot Deployment (3)