前言
之前在Idea用spring框架写代码的时候,总是修改了再重启,改了不对再改,再重启,很是耗费精力。今天学到了Idea开启devtool热部署工具,在这里总结一下。
配置步骤
1、 pom文件里添加 spring-boot-devtools依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
optional参数了解
假如你的Project A的某个依赖D添加了<optional>true</optional>
,当别人通过pom依赖Project A的时候,D不会被传递依赖进来。当你依赖某各工程很庞大或很可能与其他工程的jar包冲突的时候建议加上该选项,可以节省开销,同时减少依赖冲突
2、 pom文件添加spring-boot-maven-plugin插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
3、 File-> Settings->Build,Execution,Deployment->Compiler,勾选下面4个
4、 Ctrl+Shift+Alt+/ ,点击Register,勾选下面2个
5、 重启Idea
你会发现修改了代码,下面run窗口会自动重新编译运行