Spring Boot hot deployment when implementing development

Hot deployment principle:

It listens to changes if there are Class file, it will create a new ClaassLoader loading the file, through a series of process, the final result will be presented in front of us.

Class loading mechanism:

Compiled Java classes may be compiled into the code stored in the Class file byte code, the Class file stores a variety of information, eventually to be loaded into the virtual machine operational use. The virtual machine data that describes the classes loaded from Class file into memory, and verify the data, and converts parsing initialization, forming Java type can be used as a virtual machine.

Spring Boot achieve the development of hot deployment:

Spring Boot the following ways to achieve hot deployment

Use Spring Loaded
using spring-boot-devtools

Spring Loaded
in this way in the form of Maven plug-ins to load, so when you start using mvn spring-boot by Maven command: run start, but will start by Application.run ineffective way, because when you start the application through, has bypasses the Maven plug-in mechanism.
pom integrated approach:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

spring-boot-devtools
this way no matter how start the application, you can modify the file after reaching restart the application.
pom integration:

<! - Thermal deployment module ->
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Boot-Spring-DevTools </ the artifactId>
<optional> to true </ optional> <! - this the deployment needs to be true effective heat ->
</ dependency>
integration considerations
if it is found there is no heat effect deployment, check the IDE configuration has not opened automatically compiled.
If you use Thymeleaf template engine, template requires the default cache is set to false

# Disable thymeleaf cache (recommended: the development environment is set to false, build environment is set to true)
spring.thymeleaf.cache = false

1. For devtools can specify a directory or exclude the directory for hot deployment
to add the directory file # require restart
spring.devtools.restart.additional-Paths = src / main / the Java
file # exclude the directory does not need to restart
spring.devtools .restart.exclude = static / **, public / **

Set idea made him realize the project file to modify the automatic restart
Preferences 1. find the idea of -> Build, Execution, Deployment - > Compiler, check the Automatically Project Build
2. Back to the idea of normal interface, Mac shortcut keys shift + option + command + / shortcut keys on the window is Shift + Ctrl + Alt + /, open the Registry, check
compiler.automake.allow.when.app.runningcompiler.automake.allow.when.app.running
can not be restarted by setting the above services loading html in the case, but if you modify the java file, the service will automatically restart after a few seconds, if you do not want to restart the service needs to be added in application.properties or application.yml in spring.devtools.reatart.enable = false

 

Guess you like

Origin www.cnblogs.com/yxfcnbg/p/11547433.html