1.添加devtools组件jar包到项目中
在pom文件添加依赖如下
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
如果是微服务项目要添加到子模块中
2.添加插件到项目pom文件
添加maven插件到项目中,在pom文件中添加内容如下
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
如果是微服务项目直接添加到父工程既可
3.设置idea自动编译
依次点击:
settings->Build,Execution…->Compiler
将A D B C开头的几个选项全部勾选上,应用设置
4.更新value
同时按快捷键:Ctrl+Shift+Alt+/四个按钮,会弹出来选项框,选择第一个Registry,
弹出界面将compiler.automake.allow.when.app.running和actionSystem.assertFocusAccessFromEdt两个选项勾选上
5.重启idea
以上4步完成之后重启idea既可生效,修改完代码ctrl+s项目既可重新编译