Spring Boot Hot Deployment (3)

Source: Internet
Author: User

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)

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.