1,pom.xml中添加配置
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.0.3.RELEASE</version>
<optional>true</optional>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 没有该配置,devtools 不生效 -->
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
注意: spring-boot-devtools 的版本和spring-boot-starter-parent 的版本不能冲突,最好一致
2,在idea中配置
1)setting –> compiler 将 Build project automatically 勾选上
2) alt + shift + ctrl + / 搜索 registry 选第一个,弹出框后下拉找到 compiler.automake.allow.when.app.running 勾选上即可。
至此,热部署已解决
注意:
只有在debug模式和项目未启动 这两种状态,热部署才可用