SpringBoot 4. SpringBoot integrates devtools for hot deployment and springbootdevtools

Source: Internet
Author: User

SpringBoot 4. SpringBoot integrates devtools for hot deployment and springbootdevtools

1. Add devtools Dependencies

<! -- Spring boot hot deployment: this hot deployment will encounter a java. lang. ClassCastException --> <! -- Optional = true: the dependency is not passed. This project depends on devtools. If you want to use devtools for projects that depend on the myboot project, you need to re-introduce --> <dependency> <groupId> org. springframework. boot </groupId> <artifactId> spring-boot-devtools </artifactId> <optional> true </optional> </dependency>

After devtools is configured, any file project modified in classpath will be automatically restarted.

(1) Some resources do not need to be restarted when they are changed. For example, the Thymeleaf template can be edited locally. By default, the following resource paths are changed:/META-INF/maven,/META-INF/resources,/resources,/static,/publicOr/templates A restart is not triggered, but a real-time reload is triggered.

If you exclude these paths in reverse order, you can use the following Configuration:

Spring. devtools. restart. exclude = static/**, public /**

(2) If you want to retain these default values and add other exclusion items, use the spring. devtools. restart. additional-exclude attribute instead.

(3) through System. setProperty ("spring. devtools. restart. enabled", "false"); method, you can run angel in SpringApplication. run () method to disable devtools.

(4) When we start App. java again, the restartedMain loader is used, indicating that hot deployment has been successful.

Note: Due to the dual-class loading mechanism of devtools, java. lang. ClassCastException may occur after the common er is combined (for example:class x.x.A cannot be cast to x.x.A.).

The solution is as follows:

Insrc/main/resourcesCreate a META-INF directory, under which you add a spring-devtools.properties configuration with the following content:

  restart.include.mapper=/mapper-[\\w-\\.]+jar  restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar


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.