亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spring Cloud工程搭建過程詳解

 更新時(shí)間:2025年02月19日 10:32:42   作者:新綠MEHO  
文章介紹了如何使用父子工程搭建SpringCloud項(xiàng)目,包括創(chuàng)建父工程和子項(xiàng)目,以及管理依賴版本,感興趣的朋友一起看看吧

工程搭建

因?yàn)椴鸱殖闪宋⒎?wù),所以要拆分出多個(gè)項(xiàng)目,但是IDEA只能一個(gè)窗口有一個(gè)項(xiàng)目,為了解決這個(gè)問題,我們采用父子工程搭建。

搭建父子工程

創(chuàng)建父工程

1. 創(chuàng)建?個(gè)空的Maven項(xiàng)?, 刪除所有代碼, 只保留pom.xml

2. 完善pom?件

使?properties來進(jìn)?版本號(hào)的統(tǒng)?管理, 使?dependencyManagement來管理依賴, 聲明??程的打包?式為pom.

<?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>com.wmh</groupId>
    <artifactId>spring-cloud-demo1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>order-service</module>
        <module>product-service</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <java.version>17</java.version>
        <mybatis.version>3.0.3</mybatis.version>
        <mysql.version>8.0.33</mysql.version>
        <spring-cloud.version>2022.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.version}</version>
            </dependency>
            <dependency>
                <groupId>com.mysql</groupId>
                <artifactId>mysql-connector-j</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter-test</artifactId>
                <version>${mybatis.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

DependencyManagement 和 Dependencies:

1. dependencies :將所依賴的jar直接加到項(xiàng)?中. ?項(xiàng)?也會(huì)繼承該依賴.
2. dependencyManagement :只是聲明依賴, 并不實(shí)現(xiàn)Jar包引?. 如果?項(xiàng)?需要?到相關(guān)依賴,需要顯式聲明. 如果?項(xiàng)?沒有指定具體版本, 會(huì)從?項(xiàng)?中讀取version. 如果?項(xiàng)?中指定了版本號(hào),就會(huì)使??項(xiàng)?中指定的jar版本. 此外??程的打包?式應(yīng)該是pom,不是jar, 這?需要?動(dòng)使? packaging 來聲明.

SpringBoot 實(shí)現(xiàn)依賴jar包版本的管理, 也是這種?式 

依賴Jar的版本判斷

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.mysql</groupId>
                <artifactId>mysql-connector-j</artifactId>
                <version>${mysql.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

上述代碼中, lombok 會(huì)被直接引?到當(dāng)前項(xiàng)?以及?項(xiàng)?中, mysql-connector-j 不會(huì)實(shí)際引?jar,
?項(xiàng)?繼承時(shí)必須顯式聲明.

Spring Cloud版本

Spring Cloud 是基于SpringBoot搭建的, 所以Spring Cloud 版本與SpringBoot版本有關(guān) 。

創(chuàng)建子項(xiàng)目-訂單服務(wù)

聲明項(xiàng)?依賴 和 項(xiàng)?構(gòu)建插件

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
        </dependency>
        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

創(chuàng)建子項(xiàng)目-商品服務(wù)

聲明項(xiàng)?依賴 和 項(xiàng)?構(gòu)建插件

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
        </dependency>
        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

到此這篇關(guān)于Spring Cloud工程搭建的文章就介紹到這了,更多相關(guān)Spring Cloud工程搭建內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java利用DOM解析XML的學(xué)習(xí)指南

    Java利用DOM解析XML的學(xué)習(xí)指南

    在Java中使用DOM解析XML文件是一個(gè)常見的操作,它允許你以編程方式讀取、修改和保存XML文檔的結(jié)構(gòu)和內(nèi)容,本文為大家介紹了具體的實(shí)現(xiàn)步驟,有需要的小伙伴可以參考下
    2025-04-04
  • Java 棧與隊(duì)列超詳細(xì)分析講解

    Java 棧與隊(duì)列超詳細(xì)分析講解

    這篇文章主要介紹了Java數(shù)據(jù)結(jié)構(gòu)中的棧與隊(duì)列,在Java的時(shí)候,對(duì)于棧與隊(duì)列的應(yīng)用需要熟練的掌握,這樣才能夠確保Java學(xué)習(xí)時(shí)候能夠有扎實(shí)的基礎(chǔ)能力。本文小編就來詳細(xì)說說Java中的棧與隊(duì)列,需要的朋友可以參考一下
    2022-04-04
  • spring配置文件加密方法示例

    spring配置文件加密方法示例

    這篇文章主要介紹了spring配置文件加密方法示例,簡單介紹了什么是配置文件,然后分享了在實(shí)際生產(chǎn)環(huán)境中,對(duì)配置文件不允許出現(xiàn)明文用戶名及密碼等信息需求的Java實(shí)現(xiàn)代碼,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • java性能優(yōu)化之代碼緩存優(yōu)化

    java性能優(yōu)化之代碼緩存優(yōu)化

    這篇文章主要介紹了java性能優(yōu)化之代碼緩存優(yōu)化,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-07-07
  • Spring自動(dòng)注入失敗的解決方法

    Spring自動(dòng)注入失敗的解決方法

    這篇文章主要介紹了Spring自動(dòng)注入失敗的解決方法,幫助大家更好的理解和學(xué)習(xí)使用Spring框架,感興趣的朋友可以了解下
    2021-05-05
  • Springboot中的@ComponentScan注解使用解析

    Springboot中的@ComponentScan注解使用解析

    這篇文章主要介紹了Springboot中的@ComponentScan注解使用解析,@ComponentScan用于類或接口上主要是指定掃描路徑,spring會(huì)把指定路徑下帶有指定注解的類注冊(cè)到IOC容器中,需要的朋友可以參考下
    2024-01-01
  • Java轉(zhuǎn)換流(InputStreamReader/OutputStreamWriter)的使用

    Java轉(zhuǎn)換流(InputStreamReader/OutputStreamWriter)的使用

    本文主要介紹了Java轉(zhuǎn)換流(InputStreamReader/OutputStreamWriter)的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • Springboot如何根據(jù)實(shí)體類生成數(shù)據(jù)庫表

    Springboot如何根據(jù)實(shí)體類生成數(shù)據(jù)庫表

    這篇文章主要介紹了Springboot如何根據(jù)實(shí)體類生成數(shù)據(jù)庫表的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • SpringBoot3實(shí)現(xiàn)Gzip壓縮優(yōu)化的技術(shù)指南

    SpringBoot3實(shí)現(xiàn)Gzip壓縮優(yōu)化的技術(shù)指南

    隨著 Web 應(yīng)用的用戶量和數(shù)據(jù)量增加,網(wǎng)絡(luò)帶寬和頁面加載速度逐漸成為瓶頸,為了減少數(shù)據(jù)傳輸量,提高用戶體驗(yàn),我們可以使用 Gzip 壓縮 HTTP 響應(yīng),本文將介紹如何在 Spring Boot 3 中實(shí)現(xiàn) Gzip 壓縮優(yōu)化,需要的朋友可以參考下
    2025-04-04
  • Mybatis攔截器實(shí)現(xiàn)公共字段填充的示例代碼

    Mybatis攔截器實(shí)現(xiàn)公共字段填充的示例代碼

    本文介紹了使用Spring Boot和MyBatis實(shí)現(xiàn)公共字段的自動(dòng)填充功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12

最新評(píng)論