環境變量我配置的Spring配置雲服務器這樣的:Spring雲配置服務器。在性能
@SpringBootApplication
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class, args);
}
}
我使用「天然」配置文件,以便屬性從文件系統拿起:
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.search-locations: classpath:/global
現在棘手部分屬性包含環境變量。在屬性「全球/ application-production.properties」可以這樣來配置:
test=${DOCKER_HOST}
當我啓動配置服務器 - 一切正常。然而,當我訪問http://localhost:8888/testapp/production我看到這一點:
{
name: "testapp",
profiles: [
"production"
],
label: null,
version: null,
propertySources: [
{
name: "classpath:/global/application-production.properties",
source: {
test: "${DOCKER_HOST}"
}
}
]
}
所以從ENV變量值而不是取代$ {} DOCKER_HOST而把返回的。
但是,如果我訪問http://localhost:8888/application-production.properties那麼結果就是非JSON而是純文本:
test: tcp://192.168.99.100:2376
春文件說:
的YAML和屬性表示有一個附加的標誌(一個布爾值規定查詢參數resolvePlaceholders)以標誌Spring $ {...}形式表示源文檔中佔位符的信號應在渲染前儘可能在輸出中解析。對於不瞭解Spring佔位符約定的消費者來說,這是一個有用的功能。
出於某種原因resolvePlaceholders沒有爲JSON表示工作因而服務器配置的客戶端需要知道服務器上配置的所有ENV變量。
是否可以強制JSON表示resolvePlaceholders與純文本(屬性)表示法相同?