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