Spring boot implements a hot deployment at development time (automatically restarts the app after the file is saved at development time)

Source: Internet
Author: User

What is hot deployment?

We all know that in the project development process, often change the page data or modify the data structure, in order to show the effect of changes, often need to restart the application to see the effect of change, in fact, is to recompile the creation of a new class file, this file records and code and other corresponding information, The class file is then loaded by the ClassLoader of the virtual machine.

And the heat deployment is the use of this feature, it is heard if a class file changes, it will create a new claassloader to load the file, after a series of processes, the results will be presented to our eyes.

Class loading mechanism

Classes in Java can be compiled into a class file that stores bytecode, which stores a variety of information and is eventually loaded into a virtual machine to be used for running.

Class loading mechanism (excerpt from "in-depth understanding of Java virtual machines")

The virtual machine loads the data of the description class from the class file into memory, verifies the data, parses and initializes it, and eventually forms a Java type that can be used directly by the virtual machine.

Spring Boot for hot deployment

Spring boot implements a hot deployment in the following ways:

    • Using Spring Loaded
    • Using Spring-boot-devtools

Spring Loaded

This method is loaded in the form of a Maven plugin, so booting with the MAVEN command MVN Spring-boot:run starts with the Application.Run mode, because the MAVEN plugin mechanism has been bypassed when the application starts.

Pom Integration Method:

<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 you start the app, you can restart the app after you've modified the file.

Pom Integration Method:

<!--Thermal Deployment Module -<Dependency>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-devtools</Artifactid>    <Optional>True</Optional> <!--this needs to be true for hot deployment to be effective -</Dependency>

Integration Note:

1. If no thermal deployment effect is found, you will need to check that automatic compilation is turned on in the IDE configuration.

2. If you use the Thymeleaf template engine, you need to set the template default cache to False

#禁止thymeleaf缓存 (Recommended: The development environment is set to false, the build environment is set to true) Spring.thymeleaf.cache=false

3, for Devtools can specify directory or exclude directory for hot deployment

#添加那个目录的文件需要restartspring. devtools.restart.additional-paths=src/main/java# Files that exclude that directory do not need restartspring.devtools.restart.exclude=static/**,public/**

4, by default,/meta-inf/maven,/meta-inf/resources,/resources,/static,/templates,/public files under these folders will not restart the app, But it reloads (devtools embedded a livereload Server, and when the resource changes, the browser refreshes)

5. Configure Spring.devtools.restart.enabled=false in Application.properties, at which time the restart ClassLoader is initialized, but the file updates are not monitored. System.setproperty ("spring.devtools.restart.enabled", "false") is called before Sprintapplication.run, and restart support can be turned off completely.

Reference:

Http://www.cnblogs.com/magicalSam/p/7196355.html

http://blog.csdn.net/je_ge/article/details/53326525

Http://www.jb51.net/article/112473.htm

Http://www.cnblogs.com/lspz/p/6832358.html

Spring boot implements a hot deployment at development time (automatically restarts the app after the file is saved at development time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.