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