Java 如何从Spring Boot Config Server提供的其他属性文件中的application.properties获取密钥?

Java 如何从Spring Boot Config Server提供的其他属性文件中的application.properties获取密钥?,java,spring,spring-boot,spring-boot-configuration,Java,Spring,Spring Boot,Spring Boot Configuration,Spring集中式配置的官方教程()说: 它还将发送任何名为 Git存储库中的application.properties或application.yml 我想在特定属性文件a-bootiful-client.properties中使用该文件中的一些属性 可能吗?我试过了,但占位符对我不起作用 例如,我在application.properties文件中有一个键值对key1=val1。然后在a-bootiful-client.properties文件中,我试图以other.key=${key1}

Spring集中式配置的官方教程()说:

它还将发送任何名为 Git存储库中的application.properties或application.yml

我想在特定属性文件
a-bootiful-client.properties
中使用该文件中的一些属性

可能吗?我试过了,但占位符对我不起作用

例如,我在application.properties文件中有一个键值对
key1=val1
。然后在
a-bootiful-client.properties
文件中,我试图以
other.key=${key1}-extral
的身份访问该键


谢谢

如果您在Spring项目中使用
引导.properties
文件,并将其放置在
应用程序.properties
(src/main/resources)旁边,这是可能的。此属性字段在应用程序引导期间加载,您可以执行以下操作:

# content of your bootstrap.properties
spring.application.name=a-bootiful-client
spring.cloud.config.uri=YOUR-CONFIG-SERVER-URI
key1=value1
将以下内容添加到
a-bootiful-client.properties文件中:

# content of your a-bootiful-client.properties file in your Git repo

another.key=${key1}-extraVal
现在,您可以访问Spring应用程序代码中的
另一个.key
值,如:

@Value("${another.key}")
private String myOtherKey;

这些值将被浓缩。

到底是什么不起作用?
是否是另一个.key
解析为值
${key}-extral
(即未正确解析),或者您的应用程序甚至无法获取另一个.key
key1=value1
是一种常见的配置,我想在配置服务器中定义它。放置该值的最佳位置是spring引导配置的application.properties。