1. 程式人生 > 其它 >【Java】【SpringBoot】CP03:熱部署

【Java】【SpringBoot】CP03:熱部署

IDEA java springboot 熱部署

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

注意,新版本的這個設定不在這裡,新版本的操作如下所示

參考:https://www.cnblogs.com/fanqisoft/p/15200894.html

測試熱部署

1.執行專案

2.直接修改HelloController類中返回的字串,儲存,當控制檯出現反應的時候,說明自動部署了,此時重新整理網頁

我最開先修改,儲存,重新整理,沒變化以為沒成功,後來發現是熱部署他只是反應比較慢……

等等再重新整理(等控制檯出現變化)在重新整理就可以了

作者:萌狼藍天,轉載請註明原文連結:https://www.cnblogs.com/mllt/p/springboot20220301cp3.html | 萌狼藍天@嗶哩嗶哩 | QQ:3447902411(僅限技術交流,新增請說明方向)| 歡迎關注我的嗶哩嗶哩