1.创建热部署的工程
1.1.pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<groupId>com.qf</groupId>
<artifactId>10_springboot_devtools</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- springBoot的启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- thymeleaf的启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
</project>
1.2.controller
/**
* SpringBoot----SpringLoader
*/
@Controller
public class ShowController {
@RequestMapping("/show")
public String showPage(){
System.out.println("ShowPage......");
return "index";
}
}
1.3.thymeleaf
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<span th:text="Hello...."></span>
</body>
</html>
1.4.App
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
2.使用DevTools进行热部署
2.1.添加devtools启动器
<!-- DevTools的启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
2.2.设置idea自动编译
2.3.设置idea运行时编译
1、Shift+Ctrl+Alt+/,选择Registry(Mac 的快捷键是:Command+Shift+option+/)
2、找到compiler.automake.allow.when.app.running打勾,并点击close
2.4.测试
分别修改后台和Thymeleaf代码,观察是否热部署
2.5.总结
devtools是重新启动,不属于真正的热部署
3.SpringBoot的Run Dashboard
3.1.Run Dashboard是什么
可以同时显示多个springboot项目,非常方便
默认情况下,idea的run dashboard是关闭的,当检测到有多个springboot项目时会弹出提示框,询问是否打开。
3.2.打开Run Dashboard
idea的项目目录中,有一个.idea目录下有一个workspace.xml
打开,搜索Rundashboard,找到下面这段:
然后在Component中添加下面的内容:
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
3.3.关闭Run Dashboard
找.idea目录下workspace.xml的Component,删除下面的内容:
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>