springcloud~nacos中的共(gong)享配置文件
共(gong)(gong)享配(pei)置(zhi)文件,即多個(ge)應用配(pei)置(zhi)中(zhong)有共(gong)(gong)同(tong)的配(pei)置(zhi)項,如redis,mysql,hystrix等等,這(zhe)些公共(gong)(gong)配(pei)置(zhi),我們可以抽象出來(lai),通(tong)過nacos的shared-configs來(lai)共(gong)(gong)享。
注意
共享配置,需要有擴展名,我們以yaml為例,添加一個例子
const.yaml
const:
email: xxxf@sina.com
我添加了幾個共享配置,如圖

應用程序里的配置
這個(ge)shared配置(zhi)需(xu)要在應用(yong)程序(xu)的bootstrap文件(jian)里配置(zhi)
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
在測試時,可(ke)以(yi)直(zhi)接拿(na)到const.yaml里的配置(zhi)項
@Value("${const.email:test@sina.com}")
String email;