Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署

10.1.1 模板热部署

在Spring Boot里,模板引擎的页面默认是开启缓存的,如果修改了页面的内容,则刷新页面是得不到修改后的页面的,因此我们可以在application.properties中关闭模板引擎的缓存,例如:
Thymeleaf的配置:

spring.freemarker.cache=false

Groovy的配置:

spring.groovy.template.cache=false

Velocity的配置:

spring.velocity.cache=false

10.1.2 Spring Loaded

Spring Loaded可实现修改类文件的热部署。下载Spring Loaded,地址为:http://repo.spring.io/simple/libs-release-local/org/springframework/springloaded/1.2.3.RELEASE/springloaded-1.2.3.RELEASE.jar,安装单击Run Config urations…。如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署
在Arguments标签而的 vm arguments中填入如下内容,注意下面指定的是springloaded的路径;
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署

10.1.3 JRebel

JRebel是Java开发热部署的最佳工具,其对Spring Boot也提供了极佳的支持。JRebel为收费软件,可试用14天。

(1)安装

打开EclipseMarketPlace,如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署
检索JRebel,并安装,如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署
重启STS,即可完成安装。

(2)配置使用

选定Spring Boot,增加JReblel功能,
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署
此时为我们添加了一个rebel.xml,用来配置热部署内容,如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署

JRebel会对D:\Documents\workspace-spring-tool-suite-4-4.1.0.RELEASE\ch10\target\classes目录下的文件进行热部署

首次启动会询问是否以JRebel启动程序,如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署
当启动时出现和JRebel相关的信息,表明配置成功,如图
Spring Boot实战(十)Spring Boot开发部署与测试 10.1 开发的热部署

10.1.4 spring-boot-devtools

在Spring Boot项目中添加spring-boot-devtools依赖即可实现页面和代码的热部署。

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
		</dependency>