SpringCloud 提供純文本

2023-08-02 10:10 更新

除了使用?Environment?抽象(或YAML或?qū)傩愿袷降某橄蟊硎局唬┲?,您的?yīng)用程序可能需要根據(jù)其環(huán)境量身定制的通用純文本配置文件。Config Server通過(guò)位于?/{application}/{profile}/{label}/{path}?的附加終結(jié)點(diǎn)提供了這些終結(jié)點(diǎn),其中?application?,?profile?和?label?與常規(guī)環(huán)境終結(jié)點(diǎn)具有相同的含義,但是path是指向以下環(huán)境的路徑文件名(例如?log.xml?)。該端點(diǎn)的源文件與環(huán)境端點(diǎn)的定位方式相同。屬性和YAML文件使用相同的搜索路徑。但是,不是匯總所有匹配資源,而是僅返回第一個(gè)要匹配的資源。

找到資源后,可通過(guò)對(duì)提供的應(yīng)用程序名稱,配置文件和標(biāo)簽使用有效的?Environment?來(lái)解析常規(guī)格式(?${…?}?)的占位符。通過(guò)這種方式,資源端點(diǎn)與環(huán)境端點(diǎn)緊密集成在一起??紤]以下用于GIT或SVN存儲(chǔ)庫(kù)的示例:

application.yml
nginx.conf

?nginx.conf?如下所示:

server {
    listen              80;
    server_name         ${nginx.server.name};
}

和?application.yml?像這樣:

nginx:
  server:
    name: example.com
---
spring:
  profiles: development
nginx:
  server:
    name: develop.com

?/foo/default/master/nginx.conf?資源可能如下:

server {
    listen              80;
    server_name         example.com;
}

和?/foo/development/master/nginx.conf?像這樣:

server {
    listen              80;
    server_name         develop.com;
}

用于環(huán)境配置的源文件一樣,profile用于解析文件名。因此,如果要使用特定于配置文件的文件,可以通過(guò)名為logback-development.xml(優(yōu)先于logback.xml)的文件來(lái)解析/*/development/*/logback.xml。

如果不想提供label并讓服務(wù)器使用默認(rèn)標(biāo)簽,則可以提供useDefaultLabel請(qǐng)求參數(shù)。因此,default配置文件的前面的示例可以是/foo/default/nginx.conf?useDefaultLabel。


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)