Spring Cloud Alibaba nacos 配置中心使用

Spring Cloud Alibaba 使用nacos 注册中心

背景

在第一篇nacos介绍的时候提到nacos 是注册中心又是配置中心,上一篇我们介绍了Spring Cloud Alibaba 使用nacos 注册中心的使用这一篇我们讲述 配置中心的使用。

nacos配置中心

之前的讲述了 配置文件的配置。这次我们只需要在之前的代码中 添加maven nacos配置中心的依赖这个是配置到spring cloud alibaba 教程总pom版本控制 这个pom文件中。这样还是利用maven 自身的jar包依赖。discovery-server、cloud-discovery-client-common俩个模块自动引入nacos配置中心的依赖

       <!-- nacos config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

修改对应yml文件添加

server端yaml配置文件

spring:
    cloud:
      config:
        server-addr: 47.99.209.72:8848
        file-extension: yaml

最后分别呈现结果

server:
  port: 9012

spring:
  profiles:
    active: dev
  application:
    name: cloud-discovery-server
  cloud:
    nacos:
      config:
        server-addr: 47.99.209.72:8848
                #指定文件后缀
        file-extension: yaml
      discovery:
        server-addr: 47.99.209.72:8848

修改http接口

package com.xian.cloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import or
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值