Nacos配置中心cloud配置启动

  • Post author:
  • Post category:其他



Nacos配置注册中心:

server:
  port: 8888

spring:
  application:
    name: home
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
      config:
        #主要是需要优先加载Nacos
        allow-override: true
        override-none: false
        override-system-properties: true
        #主要是需要优先加载Nacos

        server-addr: ${spring.cloud.nacos.discovery.server-addr}
        file-extension: yaml
        #主要是支持多配置文件
        shared-configs:
          - data-id: application-dev.yaml
            refresh: true

目前主要支持cloud版本是:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

需要引起Nacos的服务发现和配置中心:

<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>


<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>
                    <!-- spring cloud 依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- spring cloud alibaba 依赖 -->
            <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>
        </dependencies>
    </dependencyManagement>
 <!--注册中心客户端-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!--配置中心客户端-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <!--feign 依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <!-- okhttp 扩展 -->
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-okhttp</artifactId>
        </dependency>
        <!-- LB 扩展 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
<!-- 

最新使用版本需要考虑优先加载Nacos配置
 -->

<spring-boot.version>2.6.6</spring-boot.version>-->
<spring-cloud.version>2021.0.1</spring-cloud.version>-->
<spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>



版权声明:本文为iteye_7129原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。