springBoot对调试支持很好,修改之后可以实时生效,需要在 pom.xml 中添加以下配置:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-devtools</artifactId>
  5. <optional>true</optional>
  6. </dependency>
  7. </dependencies>
  8. <build>
  9. <plugins>
  10. <plugin>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-maven-plugin</artifactId>
  13. <configuration>
  14. <fork>true</fork>
  15. </configuration>
  16. </plugin>
  17. </plugins>
  18. </build>

键入Ctrl + Alt + Shift + / 选择 Registry...,勾选 compiler.automake.allow.when.app.running
006.png
File | Settings | Build, Execution, Deployment | Compiler 勾选 Build project automatically
007.png

最后, 编辑运行时配置, 选择 Update classes and resources
004.png

以上只是热重启, 如果要彻底解决热更新的问题, 请使用 spring-loadedJRebel

禁用重启

public static void main(String[] args) {
    System.setProperty("spring.devtools.restart.enabled", "false");
    SpringApplication.run(MyApp.class, args);
}

LiveReload

spring-boot-devtools 模块包含一个内嵌的LiveReload服务器,它可以在资源改变时触发浏览器刷新。LiveReload浏览器扩展可以免费从 livereload.com 站点获取,支持Chrome,Firefox,Safari等浏览器。