Eclipse Spring boot for hot deployment

Source: Internet
Author: User

Spring provides developers with a module called Spring-boot-devtools to enable the spring 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 was discarded and re-created a restart ClassLoader, which resulted in a faster restart time due to fewer classes to load.

Use the following configuration to add:

<dependencies>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-devtools</artifactid>
<optional>true</optional>
</ Dependency>
<dependency>
<groupid>org.springframework.boot</groupid>
< Artifactid>spring-boot-starter-web</artifactid>
</dependency>

<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-test</ Artifactid>
<scope>test</scope>
</dependency>
</dependencies>

< Build>
<plugins>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
<configuration>
<fork>true< /fork>
</configuration>
</plugin>
</plugins>
</build>

You must set the following:

Eclipse–> project–> Build automatically to be checked, the unchecked words do not work.

Description

(1) Devtools can implement the page hot deployment (that is, the page modification will take effect immediately, this can be directly configured in the Application.properties file Spring.thymeleaf.cache=false to implement),
Implement a hot deployment of the properties file by implementing a class file hot deployment that does not take effect immediately after the class file is modified.
That is, Devtools will listen for file changes under Classpath, and will immediately restart the application (taking place at save time), note: Because of its virtual machine mechanism, the restart is very fast
(2) After the configuration of the Java file is also supported after the hot start, but this method is a project restart (faster project restart), will clear the session value, that is, if a user login, the project will need to re-login after restart.

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).

Configuration of the Devtools

When you configure Spring.devtools.restart.enabled=false in application.properties, the restart ClassLoader is also initialized, but the file updates are not monitored.
Call System.setproperty ("spring.devtools.restart.enabled", "false") before Sprintapplication.run, and you can completely turn off restart support and configure the content:

#热部署生效
Spring.devtools.restart.enabled:true
#设置重启的目录
#spring. Devtools.restart.additional-paths:src/main/java
#classpath目录下的WEB-inf folder content modification does not restart
spring.devtools.restart.exclude:web-inf/**

Test

    • Modify Class –> Save: App Restarts
    • Modify configuration file –> Save: app will restart
    • Modify Page –> Save: The app will not restart, but will reload, the page will refresh (the principle is to set Spring.thymeleaf.cache to False, refer to: Spring Boot configuration template engine)

Eclipse Spring boot for hot deployment

Related Article

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.