How springboot achieve hot deployment

web development process springboot, we often need a lot of time to restart the web server to ensure that the modified source code files, such as xml or configuration files, as well as some static files take effect, so time-consuming and inefficient. We can use hot deployment way to solve such problems. Hot deployment means that we do not need to restart the web server can ensure that the files that were modified with immediate effect.

springboot There are three ways to achieve hot deployment:

1. springloaded pom.xml configuration file, use mvn spring-boot: run start

2. Use springloaded loaded locally-up and configuration parameters jvm

-javaagent: <jar packet address> -noverify

3. Use devtool kit, simple operation, but every time you need to re-deploy

The first :

1. The original file, add the following configuration pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>springloaded</artifactId>
    <version>1.2.8.RELEASE</version>
</dependency>

Note: You need to add dependency in spring-boot-maven-plugin in

2. Start mode is changed to start maven

In the project folder dos window enter the command: mvn spring-boot: run

Note: Stopping the service can only use ctrl + c, if you set the background to start, you need to kill the process

The second :

1. The second and first used in the same manner, but it needs to download spring-loaded,

The following code in this board VM arguments, as shown:

-javaagent:D:\maven_jar\springloaded-1.2.8.RELEASE.jar -noverify

Note: The red word location where your jar package

He explained: -javaagent: command followed by a colon, which means the implementation of a specific code before executing the main method

            Close -noverify java bytecode verification function

 And then directly run started on the line.

Third :

1. Add a hot deployed in pom.xml dependency,

<!-- 热部署 -->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
</dependency>

To start the project.

summary:

       The third test is desirable in a development environment, and convenient.

      In a production environment, it is recommended to use the second, using a script to start.

springboot implement the principle of hot deployment of:

       Deep principle is the use of two ClassLoader, ClassLoader to load those classes will not be a change in the (third-party jar package), another class ClassLoader to load changes, called the restart ClassLoader, so that when there are code changes, the original restart ClassLoader is discarded, a re-build the restart ClassLoader, since small compared to load class, to achieve a rapid restart time.

If insufficient, welcome message corrections, please keep. . .

Published 171 original articles · won praise 1 · views 10000 +

Guess you like

Origin blog.csdn.net/duan196_118/article/details/105346250