从Spring Cloud配置服务器加载多个配置文件

时间:2018-06-29 06:43:15

标签: spring-boot spring-cloud

嘿,我知道如何检查配置服务器中的属性,即 http:// {配置服务器URL}:{Port} / {ServiceID} / {Profile}

现在,我面临一个必须从云配置服务器读取多个属性文件的问题。例如:现在我必须从单个属性文件(即employee.properties)中读取属性文件(大文件)

我不希望单个文件夹中包含大量属性文件。喜欢

employee-dev.properties
employee-dit.properties
employee-sit.properties
employee-uat.properties
employee-preprod.properties
employee-prod.properties

customers-dev.properties
customers-dit.properties
customers-sit.properties
customers-uat.properties
customers-preprod.properties
customers-prod.properties

.
.
.
and soo on.

我的要求是我需要保留属性文件列表,并且配置服务器将向我提供这些值。就像:

**{env}/employee.properties**
**{env}/customers.properties**

这里的环境可以是dit,sit,prod等任何环境。

希望我在这里得到答复。

1 个答案:

答案 0 :(得分:0)

如果您不想将所有属性文件放在一个文件夹中,那么您需要在配置服务器属性文件上添加此配置。

1。匹配所有选项

spring.cloud.config.server.native.searchLocations = [classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]

2。仅匹配/application-name/application-name-profile.properties

spring.cloud.config.server.native.searchLocations = classpath:config/{application}

然后,您将根据应用程序名称文件夹进行匹配。  资源/配置/应用程序名称/应用程序名称属性。