当前位置: 首页 > news >正文

导航网站的网站地图怎么做在线外链工具

导航网站的网站地图怎么做,在线外链工具,聊城做网站费用,php网站开发实例教程代码0. 引言 在单机架构下,我们只需要将我们的依赖在pom中引入。但是过渡到微服务架构后,会涉及到多模块引用相同的依赖,多模版之间依赖的版本太过分散难以管理的问题。 这就需要我们利用maven中依赖传递的特性,结合dependencyManage…

0. 引言
在单机架构下,我们只需要将我们的依赖在pom中引入。但是过渡到微服务架构后,会涉及到多模块引用相同的依赖,多模版之间依赖的版本太过分散难以管理的问题。

这就需要我们利用maven中依赖传递的特性,结合dependencyManagement标签来做好依赖的版本管理。下面我们就通过具体的案例来向大家演示如何在微服务架构中做好pom的管理规范。

1. 在父项目中实现版本管理
我们介绍的第一种版本管理的方案,就是在父项目中声明版本。

我们先来看我们的案例:

有一个微服务架构,包含商品模块product,订单模块order,网关模块gateway,还有一个公用模块commons。
其中商品模块、订单模块都需要引入nacos、spring web、seata、mybatis-plus、swagger、mysql、lombok依赖
订单模块中除了上述所说的依赖,还需要引入dynamic-datasource、openfeign依赖
网关模块需要引入nacos discovery、gateway、jwt、swagger、lombok依赖

1.1 在父项目中声明依赖版本
​​以下配置在父项目pom.xml中操作​​ 首先我们先将所需要的依赖的版本号定义为属性

<properties>
        <java.version>1.8</java.version>
        <maven.version>3.8.1</maven.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
        <spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version>
        <seata-version>1.4.0</seata-version>
        <swagger.version>2.9.2</swagger.version>
        <mybatis-plus.version>3.4.2</mybatis-plus.version>
</properties>

其次我们在​​dependencyManagement​​标签中将所有的依赖做好版本声明

如果不知道这些标签的作用以及用法的,可以先看专栏的上一篇博客:
​springcloud:maven快速上手 | maven常用标签(十三)​​

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>io.seata</groupId>
                <artifactId>seata-spring-boot-starter</artifactId>
                <version>${seata-version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
                <version>${seata-version}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
        </dependencies> 
    </dependencyManagement>

这里咱们要注意的是,​​spring-boot-dependencies​​​和​​spring-cloud-alibaba-dependencies​​这两个依赖实际上并不是jar包,我们点击进去就可以知道,这是一个聚合项目,里面声明了常用的依赖的版本

我们通过引用这个线程的聚合项目,节省了大量常用依赖的版本管理

其次我们再在父项目中声明一下项目的jdk、maven版本以及编码格式。如果项目中有通用的maven插件配置,也可以在这里声明

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

1.2 服务的公用依赖提取到commons模块中
​​以下配置在commons模块的pom.xml中操作​​ 基于这样的一个案例,我们首先知道的是商品模块和订单模块中都有很多相同的依赖,那么我们把这些相同的依赖添加到公用模块中,如果没有公用模块,可以创建一个,专用于存储公用的实体类、工具类、公共依赖登

首先我们需要声明父项目,以此使用父项目中声明的依赖版本

<parent>
        <artifactId>springcloud2</artifactId>
        <groupId>com.example</groupId>
        <version>1.0.0</version>
</parent>

其次将公用的依赖声明出来,这里会发现我们这里的依赖是没有声明版本的,这是因为我们已经在父项目中将版本声明好了。这也就是我们要做版本管理的意义所在

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency> 
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId> 
        </dependency> 
        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId> 
        </dependency> 
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency> 
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency> 
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency> 
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

1.3 商品、订单模块中引入commons模块
1、然后在商品模块和订单模块引入commons模块

<parent>
        <artifactId>springcloud2</artifactId>
        <groupId>com.example</groupId>
        <version>1.0.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>product-server-feign</artifactId>
    <version>${parent.version}</version>
    <name>product-server-feign</name>
    <description>product-server-feign</description>

    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>commons</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

后续就可以只在commons中添加或者修改依赖,就能实现各个模块的公用依赖统一管理

需要注意的是:​​子项目中一定要用parent标签声明好父项目​​ 2、因为订单模块中还多了其他几个依赖,所以我们除了commons外还要在订单的pom中额外引入其他依赖

<parent>
        <artifactId>springcloud2</artifactId>
        <groupId>com.example</groupId>
        <version>1.0.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>order-server-feign</artifactId>
    <version>${parent.version}</version>
    <name>${project.artifactId}</name>

    <dependencies>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>product-server-feign</artifactId>
            <version>${parent.version}</version>
        </dependency>

    </dependencies>

3、commons中的公用依赖大部分网关模块都不需要,所以我们干脆就网关模块的依赖单独引入

<parent>
        <artifactId>springcloud2</artifactId>
        <groupId>com.example</groupId>
        <version>1.0.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>gateway-token</artifactId>
    <version>${project.parent.version}</version>
    <name>${project.artifactId}</name>

    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <!-- JWT -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
        </dependency>
        <!--  swagger2      -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <!-- swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

如上我们就针对我们整个项目的各个模块做好了依赖版本管理,如果需要查看源码可以文章最后的git地址中下载

2. 在聚合项目中实现版本管理
2.1 什么是聚合项目
所谓聚合项目,就是单独的一个空maven项目,只有pom文件,专门用于依赖的版本声明,其他的项目通过引入该聚合项目来实现依赖版本管理

这个比在父项目中进行版本管理更加凸显模块的专业化

2.2 实操
1、创建一个空maven项目,只保留pom.xml文件。将该项目的打包方式声明为pom

<packaging>pom</packaging>
1.
2、然后将上述的父项目中的​​dependencyManagement​​标签中的依赖管理添加到聚合项目的pom文件中

3、在商品服务、订单服务、网关服务、commons服务中引入该聚合项目,从而实现版本的统一管理

http://www.tj-hxxt.cn/news/74850.html

相关文章:

  • 宁夏网站制作哪家好免费云服务器
  • 有哪些做网站的公司google play 安卓下载
  • 地方网站怎么做推广手机百度账号申请注册
  • 常州网站搜索排名网络推广和竞价怎么做
  • 庐江网站建设推广游戏赚钱的平台有哪些
  • 做网站seo排名是什么意思
  • WordPress商品相册幻灯片宁波企业seo外包
  • 做公众号的网站网页设计成品源代码
  • 十堰微网站建设百度指数的需求指数
  • 做网站用什么样的电脑现在疫情怎么样了最新消息
  • 网站推广的方法及特点个人网站该怎么打广告
  • 一个空间可以做多少个网站怎么自己做网页
  • 网站软文推广好处外贸建站seo
  • 洪江市网站企业营销
  • 西安草坪网站建设电商软文范例100字
  • 商城网站建设目的山东网络推广优化排名
  • 班级网站建设步骤最新搜索引擎排名
  • 搭建平台网站宁波网络推广优化方案
  • 黄岛开发区做网站的公司谷歌seo排名工具
  • 网站建设销售网站seo分析案例
  • 网站开发进度安排百度优化点击软件
  • 网站建设哪家好胆中毒开发网站多少钱
  • 做外贸雨伞到什么网站今日财经新闻
  • 用vs2010做网站论文自动推广引流app
  • 那些域名可以做后缀做网站百度销售岗位怎么样
  • 网站服务器 内容更新专业做网络推广的公司
  • 百度小程序给网站做链接互联网项目
  • 看公狍和女人做爰网站sem是什么意思?
  • 河北网站制作十大舆情网站
  • 秦皇岛哪里做网站温岭网络推广