1. dev-tool
maven依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>TestDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--devtools热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置
spring:
devtools:
restart:
enabled: true #设置开启热部署
additional-paths: src/main/java #重启目录
exclude: WEB-INF/**
freemarker:
cache: false #页面不加载缓存,修改即时生效
IDEA配置
快捷键
ctrl + alt+ shift + /
在 首字母c开头中找:
问题
看控制台打印,打印了两边banner。据我所知,这两遍banner Spring容器启动了两次。
感觉还是不太ok。
测试启动速率
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
long before = System.currentTimeMillis();
SpringApplication.run(TestApplication.class, args);
System.out.println(System.currentTimeMillis()-before);
}
}
初次启动:
热部署启动:
因为我的测试项目没什么类,但是也可明显看到启动速率减少了很多。但是实际启动速率也要考虑很多反面,热部署可能只是减少了本地类的加载速率,但是启动涉及到微服务其他方面,比如说注册服务,启动的其他预处理操作的话,可能根本就改善不了什么启动速率,因为根本就和项目是否臃肿是否无关 了。所以我想这也是为什么公司项目没有采用dev-tool的关系。
另一个路子
Control+Shift+F9进行手工免启动快速更新!!
测试和热部署容器速率差不多。
2.JRebel插件
首先就是下载安装以及破解插件,过程省略。失效请重复以下过程。
https://jrebel.qekang.com/{uuid}
UUID
设置离线工作模式:
如果上面的Dev-tool的IDEA 配置已经配置好了的话,就不用再配置了。
测试
初次启动
但是在我修改了部分代码后,貌似并没有重启。
芜湖,真乃神器。