0

The Spring official tutorial for Centralized Configuration (https://spring.io/guides/gs/centralized-configuration/) says that:

It will also send all the values from any file named application.properties or application.yml in the Git repository.

I would like to use a few properties from that file inside the specific property file a-bootiful-client.properties.

Is it possible? I tried but the placeholders did not work for me.

For example, I have a key-value pair key1=val1 in the application.properties file. Then in the a-bootiful-client.properties file I tried to access that key as another.key=${key1}-extraVal.

Thanks

The_Cute_Hedgehog
  • 1,280
  • 13
  • 22
  • What exactly did not work? Was the `another.key` resolved to the value `${key}-extraVal` (i.e. didn't properly resolve) or your application couldn't even get `another.key` at all? – randomUser56789 Dec 29 '17 at 07:28

1 Answers1

1

That is possible if you use a bootstrap.properties file in your Spring project and place it next to your application.properties (src/main/resources). This property field is loaded during the bootstrap of your application and you can do the following:

# content of your bootstrap.properties
spring.application.name=a-bootiful-client
spring.cloud.config.uri=YOUR-CONFIG-SERVER-URI
key1=value1

Add the following to your a-bootiful-client.properties file:

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

another.key=${key1}-extraVal

Now you can access the another.key value in your Spring application code like:

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

and the values will be concated.

rieckpil
  • 10,470
  • 3
  • 32
  • 56
  • `key1=value1` is a common configuration and I would like to define it in configuration server. The best place to put that value is application.properties of the spring boot config. – The_Cute_Hedgehog Dec 29 '17 at 07:53