[关闭]
@lirenmi 2017-08-15T10:34:06.000000Z 字数 776 阅读 902

使用Spring Boot 在IDEA自动重启解决方案

IDEA


IDEA工具中,使用Spring boot 的spring-boot-devtools工具不能自动重启,每次都需要rebuild project,和没有自动重启差不多。所以提供如下解决方案,可以实现IDEA使用spring-boot-devtools自动重启

1、在Spring Boot框架中先引用开发者工具依赖

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-devtools</artifactId>
  4. <optional>true</optional>
  5. </dependency>

2、idea中启用项目自动构建

3、idea中compiler.automake.allow.when.app.running 属性更改为true

1、找快捷键

2、compiler.automake.allow.when.app.running 属性更改为true

在IDEA工具中按住快捷键shift+alt+command+/ 弹出如下图:

勾选compiler.automake.allow.when.app.running选项,如下图

这样就可以修改java文件就可以自动重启

但是每次修改下java文件都重新,也会带来很大的资源消耗,可以参考下面的方法解决

4、设置特定文件触发重启

配置application.yml文件:指定特定文件更改触发重启

  1. devtools:
  2. restart:
  3. trigger-file: .trigger

注意最后的trigger-file: .trigger,这表示只有resources/META-INF/.trigger的内容变化时,才会触发重新编译及加载

这样只有修改了.trigger文件,才会自动重启

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注