使用Eclipse习惯的开发者都知道,Eclipse的html文件修改后会直接刷新到浏览器页面,无需手动重编译。最近换到Idea后发现需要重新编译才会刷新到浏览器页面,下面记录下经验。
spring-boot-devtools是一个为开发者服务的一个模块,其实干的活就是在发现代码有更改之后,重新启动应用,速度比手动停止后再启动快些。
第一步加入pom
<dependencies>
···
<!-- spring-boot-devtools -->
<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>
<version>2.1.1.RELEASE</version>
<configuration>
<!--如果没有该配置,devtools不会生效 -->
<fork>true</fork>
</configuration>
<plugin>
<plugins>
<build>
第二步Ctrl+Alt+S或
File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically”
第三步“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
注意:如果以上操作完成还没有成功热加载
修改完html后切换下窗口或者点击下任务栏就会发现