Spring boot 项目热部署

添加热部署工具devtools,在pom.xml中添加以下依赖

<!--热部署,使用次工具,修改文件之后不用手动重新启动服务-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
<!--设置为ture,不会依赖传递,以后的项目需要使用此工具时候,需要重新安装-->
    <optional>true</optional>
</dependency>

然后在application.yml中添加以下代码

#关闭缓存,实时刷新
spring:
  thymeleaf:
    #热部署生效
    cache: true
  devtools:
    restart:
      enabled: true
      #设置重启目录,添加目录的文件需要restart
      additional-paths: src/main/java
      #排除不需要的restart
      exclude: static/**,public/**,WEB-INF/**

如果项目没有application.yml,那么就是在application.properties添加以下内容

#关闭缓存,实时刷新
spring.thymeleaf.cache= true
#热部署生效
spring.devtools.restart.enabled= true
#设置重启目录,添加目录的文件需要restart
spring.devtools.restart.additional-paths: src/main/java
#排除不需要的restart
spring.devtools.restart.exclude: static/**,public/**,WEB-INF/**

application.properties优先级高于application.yml,但是后者的层次感更强,至于用哪种智者见智。

发布了10 篇原创文章 · 获赞 7 · 访问量 2355

猜你喜欢

转载自blog.csdn.net/weixin_43142423/article/details/104611221