spring boot 之热部署
热部署:当发现程序修改时自动启动应用程序。
spring boot使用的是spring-boot-devtools是一个为开发者服务的一个模块。其原理用了classLoader 其中一个加载不变的类,另一个restart ClassLoader加载变得类。
devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机)。
一、pom的依赖直接添加坐标。
<!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <!--true 不然不会生效--> <scope>true</scope> </dependency>
二、编译节点添加。
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 没有该配置,devtools 不生效 --> <fork>true</fork> </configuration> </plugin>
三、(1)设置Idea Ctrl+Alt+S(
设置WEB-INF下的jsp修改不需要重启。
当我们修改了java类后,IDEA默认是不自动编译的,而spring-boot-devtools又是监测classpath下的文件发生变化才会重启应用,所以需要设置IDEA的自动编译:
)(2)Ctrl+Shift+Alt+ /
application.yml中添加:
spring: devtools: restart: #热部署生效 enabled: true #设置重启的目录 #additional-paths: src/main/java #classpath目录下的WEB-INF文件夹内容修改不重启 exclude: WEB-INF/**
重启项目即可。
转自: https://www.cnblogs.com/bingshu/p/6876030.html
参考: https://www.cnblogs.com/aqsunkai/p/6690574.html