我有一個存在于 Hashicorp 中的外部屬性檔案,我正在使用@PropertySource注釋將它拉到 Spring Boot 。在我的 Spring Boot 應用程式中,有特定于配置application.properties檔案的檔案。現在我想要的是PropertySource配置優先于這些特定于這些組態檔的配置。
我已經通讀了 Spring Boot 外部配置檔案 - https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/boot-features-external-config.html其中提到PropertySource配置是最不偏好
@PropertySource(value="${path}",ignoreResourceNotFound = true)
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
在我的 application.properties 檔案中-
name=value
在我的外部組態檔中-
name=updatedNewValue
我想要的是檢索'updatedNewValue',而不是我得到'value'。
是否可以覆寫它?
uj5u.com熱心網友回復:
特定組態檔優先于默認組態檔。您可以在 file.properties(或 properties.yml)中使用 placename=value,并使用占位符 placename=value 將名為 file-.properties(test、prod、stage 是常見選項)的第二個檔案包含在內。
請記住在運行之前提供應用程式的組態檔作為配置。
uj5u.com熱心網友回復:
如果您想使用外部配置覆寫特定組態檔的屬性,則您的外部檔案/源必須是特定于組態檔的:(
properties-profile.properties如果它是基于檔案的)
您提到了 Hashicorp... 不確定它是 Vault 還是 Consul,但對于 Vault,您可以使用以下方法定義特定于組態檔的值:
vault write secret/application,profile foo=bar
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/368443.html
上一篇:SpringJPA關系
