版本:IntelliJ IDEA 2022.2
步骤一:开启IDEA的自动编译(静态)
file -> setting -> Build,Execution,Deployment -> Compiler -> 勾选 Build project automatically
步骤二:开启IDEA的热部署策略(非常重要)
具体步骤:顶部菜单- >Edit Configurations->SpringBoot插件->目标项目->勾选热更新。
设置完成后如下图:
步骤三:添加依赖
<!--添加热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<!--热部署配置插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--热部署配置-->
<configuration>
<!--fork:如果没有该项配置,整个devtools不会起作用-->
<fork>true</fork>
</configuration>
</plugin>
步骤三:重启服务
Debug模式启动后,浏览器访问测试修改jsp、css、java等文件是否生效,若依然不行,启动过程中,可以鼠标右键选择手动编译