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
,/public
Or/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/resources
Create 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