【Java】【SpringBoot】CP03:热部署
This article is written by Xrilang(Chinese Name:萌狼蓝天)
If you want find me ,You can contact me in BiliBili . My Bilibili name is 萌狼蓝天
Of course, you can also add my QQ(My QQ number is: 3447902411)
(Please note that your sole purpose of adding me is limited to technical exchange. I won't help you with your homework!)
萌狼蓝天 - 博客园 | 萌狼工作室 - 萌狼蓝天 (mllt.cc) | 萌狼蓝天の技术栈 | Welcome !
添加spring-boot-devtools 热部署依赖启动器
<!-- 热部署依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
配置如下
<!-- 热部署依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
我的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 https://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.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cc.mllt</groupId>
<artifactId>demo01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Edu02_CreateMySpringBootProject</name>
<description>Edu02_CreateMySpringBootProject</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 热部署依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
IDEA工具热部署设置
打开设置(file>settiings)
双击shitf键,打开下面窗口,输入Maintenance
勾选compiler.automake.allow.when.app.running
注意,新版本的这个设置不在这里,新版本的操作如下所示
测试热部署
1.运行项目
2.直接修改HelloController类中返回的字符串,保存,当控制台出现反应的时候,说明自动部署了,此时刷新网页
我最开先修改,保存,刷新,没变化以为没成功,后来发现是热部署他只是反应比较慢……
等等再刷新(等控制台出现变化)在刷新就可以了
版 权 声 明
作者:萌狼蓝天
QQ:3447902411(仅限技术交流,添加请说明方向)
转载请注明原文链接:https://www.cnblogs.com/zwj/p/springboot20220301cp3.html