IDEA中Spring Boot实现热部署

Author Avatar
子语 2018 - 01 - 04
  • 在其它设备中阅读本文章

IntelliJ IDEA 作为当下较为热门的Java IDE,当使用Spring Boot进行开发时,由于静态页面经常修改,每次重启十分麻烦。因此实现Spring Boot热部署尤为重要。

Devtools

Spring为开发者提供了spring-boot-devtools模块进行Spring Boot热部署,提高了开发效率,无需手动重启应用。使用需要在pom.xml添加如下配置:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <optional>true</optional>
</dependency>

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <fork>true</fork>
    <addResources>true</addResources>
  </configuration>
</plugin>

在application.yml中添加配置

  thymeleaf:
    cache: false   # 关闭cache,刷新即可显示新页面
  devtools:
    restart:
      enabled: true # 启用热部署
      additional-paths: src/main/resources # 设置重启目录

IDEA设置

(1)File->Settings->Compiler->Build project automatically,将其打勾。

(2)ctrl + shift + A,在检索框输入Registry,随后找到Compiler autoMake allow when app running,勾选。

重启应用,此时不论是修改java文件还是修改html文件都会自动重新加载,不会重启应用。

This blog is under a CC BY-NC-SA 3.0 Unported License
本文链接:http://yov.oschina.io/article/工具/Tool/IDEA中SpringBoot实现热部署/