本文介绍下在IDEA中项目热部署的两种方式,因为如果每次我们修改下页面的代码都需要重新启动的话那么效率就太低了。

IDEA使用SpringBoot devtools

放开配置

  在IDEA中热部署默认是没有放开的,我们需要放开设置,具体如下

  1. file – > setting – > Build,Execution,Deployment–> Compiler

SpringBoot【实现热部署-devtools】_spring

  1. Control+shift+Alt+/ 选择 Registry 选中打勾 “compiler.automake.allow.when.app.running” 。如下操作

SpringBoot【实现热部署-devtools】_ide_02

SpringBoot【实现热部署-devtools】_热部署_03

spring-boot-devtools

  添加依赖

<!-- devtools 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>


<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>

启动后修改页面内容查看

SpringBoot【实现热部署-devtools】_devtools_04

修改内容后页面刷新

SpringBoot【实现热部署-devtools】_devtools_05

SpringBoot【实现热部署-devtools】_devtools_06

修改java代码后自动重启服务,某些资源(如静态资产和视图模板)无需重新启动应用程序。

Eclipse使用SpringBoot devtools

  在eclipse中直接添加相关的依赖就可以直接使用。

<!-- devtools 热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>