• [Spring Boot] 集成Nacos


    Spring Boot 集成nacos

    Spring Boot版本

    本文采用 2.6.13 其他版本可见文末版本对应

        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.6.13version>
            <relativePath/>
        parent>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    pom配置引入

            
            <dependency>
                <groupId>com.alibaba.cloudgroupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
                <version>2021.0.5.0version>
            dependency>
            
            <dependency>
                <groupId>com.alibaba.cloudgroupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
                <version>2021.0.5.0version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    bootstrap.yml 增加配置

    server:
      port: 12009
    spring:
      application:
        name: fir-node-two-dev
      cloud:
        # nacos.core.auth.caching.enabled=true 时,开启登录校验
        # 此时需要设置 username 与 password
        # nacos.core.auth.caching.enabled=false 时,不使用用户与密码
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848
            username: nacos
            password: nacos
            service: fir-node-two-dev
          config:
            server-addr: 127.0.0.1:8848
            file-extension: yml
            username: nacos
            password: nacos
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    注意有关nacos的配置只能在放置于nacos中才能生效

    启动项目

    此时在nacos中应能看到已经有注册服务
    nacos官网
    在这里插入图片描述
    点击查看详情应该为当前Spring Boot的相关信息,其中最主要的为ip地址
    在这里插入图片描述

    版本对应关系

    可查看官方文档说明,此处只摘抄主要内容
    版本说明 · alibaba/spring-cloud-alibaba Wiki · GitHub

    版本说明Steve Rao edited this page

    on Jul 27 · 65 revisions

    *毕业版本依赖关系

    Spring Boot 3.0已发布许久,但是大多数公司的项目相关 Spring Boot 版本仍停留在 Spring Boot 2.x.x 以下,如需使用新特性,请升级为对应分支的新版本。
    为了规避相关构建过程中的依赖冲突问题,我们建议可以通过 云原生应用脚手架 进行项目创建。

    2022.x 分支

    适配 Spring Boot 3.0,Spring Cloud 2022.x 版本及以上的 Spring Cloud Alibaba 版本按从新到旧排列如下表

    Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
    2022.0.0.0*Spring Cloud 2022.0.03.0.2
    2022.0.0.0-RC2Spring Cloud 2022.0.03.0.2
    2022.0.0.0-RC1Spring Cloud 2022.0.03.0.0

    2021.x 分支

    适配 Spring Boot 2.4,Spring Cloud 2021.x 版本及以上的 Spring Cloud Alibaba 版本按从新到旧排列如下表

    Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
    2021.0.5.0*Spring Cloud 2021.0.52.6.13
    2021.0.4.0Spring Cloud 2021.0.42.6.11
    2021.0.1.0Spring Cloud 2021.0.12.6.3
    2021.1Spring Cloud 2020.0.12.4.2

    2.2.x 分支

    适配 Spring Boot 为 2.4,Spring Cloud Hoxton 版本及以下的 Spring Cloud Alibaba 版本按从新到旧排列如下表(

    Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
    2.2.10-RC1*Spring Cloud Hoxton.SR122.3.12.RELEASE
    2.2.9.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
    2.2.8.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
    2.2.7.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
    2.2.6.RELEASESpring Cloud Hoxton.SR92.3.2.RELEASE
    2.2.1.RELEASESpring Cloud Hoxton.SR32.2.5.RELEASE
    2.2.0.RELEASESpring Cloud Hoxton.RELEASE2.2.X.RELEASE
    2.1.4.RELEASESpring Cloud Greenwich.SR62.1.13.RELEASE
    2.1.2.RELEASESpring Cloud Greenwich2.1.X.RELEASE
    2.0.4.RELEASE(停止维护,建议升级)Spring Cloud Finchley2.0.X.RELEASE
    1.5.1.RELEASE(停止维护,建议升级)Spring Cloud Edgware1.5.X.RELEASE

    组件版本关系

    每个 Spring Cloud Alibaba 版本及其自身所适配的各组件对应版本如下表所示(注意,Spring Cloud Dubbo 从 2021.0.1.0 起已被移除出主干,不再随主干演进):

    Spring Cloud Alibaba VersionSentinel VersionNacos VersionRocketMQ VersionDubbo VersionSeata Version
    2022.0.0.01.8.62.2.14.9.4~1.7.0
    2022.0.0.0-RC21.8.62.2.14.9.4~1.7.0-native-rc2
    2021.0.5.01.8.62.2.04.9.4~1.6.1
    2.2.10-RC11.8.62.2.04.9.4~1.6.1
    2022.0.0.0-RC11.8.62.2.1-RC4.9.4~1.6.1
    2.2.9.RELEASE1.8.52.1.04.9.4~1.5.2
    2021.0.4.01.8.52.0.44.9.4~1.5.2
    2.2.8.RELEASE1.8.42.1.04.9.3~1.5.1
    2021.0.1.01.8.31.4.24.9.2~1.4.2
    2.2.7.RELEASE1.8.12.0.34.6.12.7.131.3.0
    2.2.6.RELEASE1.8.11.4.24.4.02.7.81.3.0
    2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE1.8.01.4.14.4.02.7.81.3.0
    2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE1.8.01.3.34.4.02.7.81.3.0
    2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE1.7.11.2.14.4.02.7.61.2.0
    2.2.0.RELEASE1.7.11.1.44.4.02.7.4.11.0.0
    2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE1.7.01.1.44.4.02.7.30.9.0
    2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE1.6.31.1.14.4.02.7.30.7.1
  • 相关阅读:
    都3年测试经验了,用例设计还不知道状态迁移法?
    ES数据库的使用
    (附源码)springboot火车票售卖系统 毕业设计 211004
    《Boosting Object Detection with Zero-Shot Day-Night Domain Adaptation》2024CVPR
    数据分析平台重点演示内容梳理
    艾美捷彗星检测试剂盒(单细胞凝胶电泳)分析原理
    PHP M题 - 技巧
    hook io异常注入
    pip install mysqlclient报错
    二维码智慧门牌管理系统:构建未来社区管理新典范
  • 原文地址:https://blog.csdn.net/qq_46554590/article/details/134717240