1、添加 DevTools 依赖
<!-- 热部署依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId>
</dependency>
2、在IDEA的菜单栏中依次选择“File”→“Settings”,进入IDEA的设置对话框,然后选择“Build,Execution,Deployment”的“Compiler”选项。在右侧勾选“Build project automatically”选项将项目设置为自动编译,然后单击“Apply”→“OK”按钮保存设置。
3、IDEA的设置对话框中,选中“Advanced Settings”选项。在右侧勾选“Compiler”下的“Allow auto-make to start even if developed application is currently running”选项,允许自动启动当前正在运行的应用程序,然后单击“Apply”→“OK”按钮保存设置。
4、效果测试
controller 代码如下,访问/hello
@RestController
public class HelloController {@GetMapping("/hello")public String hello(String name){return "Hello Spring Boot";}}
接下来,在不关闭当前项目的情况下,将HelloController类中hello()方法的返回值修改为“你好 Spring Boot”。5秒后刷新浏览器页面。