熱部署,就是在應用正在運行的時候升級軟件,卻不需要重新啟動應用。
使用springboot結合dev-tool工具,快速加載啟動應用
官方地址:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#using-boot-devtools
核心依賴包:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
添加依賴后,在ide里面重啟應用,后續修改后馬上可以生效。
pom文件中修改:
1 <dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-web</artifactId> 5 </dependency> 6 7 <dependency> 8 <groupId>org.springframework.boot</groupId> 9 <artifactId>spring-boot-devtools</artifactId> 10 <optional>true</optional> 11 </dependency> 12 </dependencies> 13 14 15 <build> 16 <plugins> 17 <plugin> 18 <groupId>org.springframework.boot</groupId> 19 <artifactId>spring-boot-maven-plugin</artifactId> 20 </plugin> 21 </plugins> 22 </build>
不被熱部署的文件
1、/META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates
2、指定文件不進行熱部署 spring.devtools.restart.exclude=static/**,public/**
3、手工觸發重啟(改代碼不重啟,通過一個文本去控制) spring.devtools.restart.trigger-file=trigger.txt
在application.properties文件中添加
#指定某些文件不進行監聽,即不會進行熱加載
#spring.devtools.restart.exclude=application.properties
#通過觸發器,去控制什么時候進行熱加載部署新的文件
spring.devtools.restart.trigger-file=trigger.txt