springBoot对调试支持很好,修改之后可以实时生效,需要在 pom.xml
中添加以下配置:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
键入Ctrl
+ Alt
+ Shift
+ /
选择 Registry...
,勾选 compiler.automake.allow.when.app.running
File | Settings | Build, Execution, Deployment | Compiler
勾选 Build project automatically
最后, 编辑运行时配置, 选择 Update classes and resources
:
以上只是热重启, 如果要彻底解决热更新的问题, 请使用 spring-loaded 或 JRebel
禁用重启
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等浏览器。