1

springcloud~nacos中的共享配置文件

 2 years ago
source link: https://www.cnblogs.com/lori/p/15893020.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

共享配置文件,即多个应用配置中有共同的配置项,如redis,mysql,hystrix等等,这些公共配置,我们可以抽象出来,通过nacos的shared-configs来共享。

共享配置,需要有扩展名,我们以yaml为例,添加一个例子
const.yaml

const:
 email: [email protected]

我添加了几个共享配置,如图

应用程序里的配置

这个shared配置需要在应用程序的bootstrap文件里配置

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.60.138:80
        namespace: zzl
      config:
        server-addr: 192.168.60.138:80
        file-extension: yaml
        namespace: zzl
        shared-configs[0]:
          data-id: actuator.yaml
          refresh: true
        shared-configs[1]:
          data-id: const.yaml
          refresh: true

在测试时,可以直接拿到const.yaml里的配置项

@Value("${const.email:[email protected]}")
String email;

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK