添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
修改idea配置
需修改idea配置 idea才会自动编译
(1)File->Setting->Compiler->勾选Build Project automatically
(2)按住ctrl + shift + alt + / ,选择Registry,勾上 Compiler autoMake allow when app running
在application.yml配置devtools
spring:
devtools:
restart:
enabled: true #设置开启热部署
additional-paths: src/main/java #重启目录
exclude: WEB-INF/**
freemarker:
cache: false #页面不加载缓存,修改即时生效
Controller测试
@RestController
public class Controller {
@RequestMapping(value = "hello")
public String hello(){
return "hello world";
}
}