Spring cloud微服务搭建(一)——maven依赖

在IDE中构建普通maven项目,作为父项目。需要新增微服务,则在项目下新建module,每一个微服务是独立的模块。

主要在父pom.xml中管理maven依赖,主要依赖如下:

  • Spring boot和Spring cloud依赖
       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${springcloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${springboot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
  • 数据库相关依赖:mybatis、mysql、druid等
      <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
  • 测试依赖:junit
       <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
  • 日志依赖:log4j、logback
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
  • 消除java代码冗余的依赖(特别适用于pojo类):
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>

以上依赖均放置于dependencyManagement依赖管理节点中。

<dependencyManagement>
    <dependencies>
     </dependencies>
</dependencyManagement>
父子项目依赖管理:

pom文件中,dependencyManagement节点表示依赖管理,统一在父项目pom.xml文件中管理版本号。

  • 子模块在引入maven依赖时,若父项目dependencyManagement中已经存在,则在 dependency节点中只需指定groupIdartifactId,IDEA会默认指向父项目中的依赖,此时不需要指定版本号。
  • 若在父项目dependencyManagement中不存在,子模块的dependency节点要指定完整的gav坐标

更多:
Spring cloud微服务搭建(二)——pojo实体类

Spring cloud微服务搭建(三)—— Spring cloud服务提供方

Spring cloud微服务搭建(四)——Spring cloud 消费方

Spring cloud微服务搭建(五)——Eureka注册服务

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值