在一般的SpringBoot项目中,每次修改类时都需要重新运行应用,对于开发者来说非常不方便。SpringBoot提供了spring-boot-devtools,它能在修改类或者配置文件的时候自动重现加载SpringBoot应用。
1.首先在项目的pom文件中导入devtools依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
2.配置属性
spring.devtools.restart.enabled=true
#需要开启热部署的文件目录
spring.devtools.restart.additional-paths=src/main/java
3.修改idea设置
1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。
2) 组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”