Spring Boot Learning Note-configuring Devtools for Hot Deployment

Source: Internet
Author: User

Write in front

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.

Configure Devtools

First, we are pom.xml adding spring-boot-devtools dependencies.

    <dependency>        <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <!-- 表示依赖不会传递 --> </dependency>

Next, modify our previous pom.xml :

 <plugin> Span class= "Hljs-tag" ><groupid>org.springframework.boot </groupid> <artifactId> Spring-boot-maven-plugin</artifactid> <configuration> <fork>true</fork> <!--without this configuration, Devtools will not take effect--</ configuration> </plugin>  

At this point, restart the app and modify the code to test.

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

With this simple configuration, Spring Boot the thermal deployment can be achieved, which improves efficiency for subsequent development.
Personal blog: https://www.howieli.cn and personal csdn Blog: http://blog.csdn.net/howieli_1995.

Resources
    • Zhao Jigang's Blog
    • Lin-Fiber Blog

Spring Boot Learning Note-configuring Devtools for Hot Deployment

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.