前言
- spring boot : 2.0.0.RELEASE
- maven
- eclipse
- 另外还需清楚什么是热部署,以及为什么要热部署。
- SpringBoot项目中实现热部署的两种方式,使得部署变得异常简单,同时两种方式也非常的简单。
使用 spring-boot-devtools 实现热启动
在pom.xml中添加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
确保在pom.xml中,包好下面这个插件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
确保 spring.devtools.restart.enable
选项开启:
#配置热热启动
spring:
devtools:
restart:
#排除修改后不用热启动
exclude: static/**
enabled: true
使用 springloaded 实现热部署
Pom.xml中直接在spring-boot插件中添加依赖即可:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
<configuration>
<mainClass>此处为入口类</mainClass>
</configuration>
</plugin>
两种方式说明
真正实现热部署的只是后者,前者只是实现了热启动。从控制台日志就可以看出来。