0

Is it possible in Spring environment to define some properties like p1 in an application-profile1.yml and then refer to ${p1} in other properties in application.yml ?

Just like an inter dependency order but between properties/yml files or properties themselves, can we do this with spring?

The purpose would be to avoid duplication when the same property like kafka bootstrap needs to go in multiple places.

NicuMarasoiu
  • 776
  • 9
  • 25

1 Answers1

0

Let's say you have 3 yml files

  1. application-dev.yml

  2. application-prod.yml

  3. application.yml

You may mention the common configurations in the application.yml file and can mention the profile specific configurations in application-{profile}.yml When you will enable the {profile} spring will consider that application-{profile}.yml file higher precedence.

Romil Patel
  • 12,879
  • 7
  • 47
  • 76
  • but is it possible to use a property defined in application-profile and use it to construct values for new properties in application.yml? for instance to publish multiple properties with the same value, and we would have the value per env only in the profile ymls but all the other names that would point to that same value would be populated in the common part. this did not work.. – NicuMarasoiu Apr 08 '21 at 17:12
  • now trying to define another profile which is used all the time but after the env profile like prod,common where application-common.yml would build new props based on profile defined ones – NicuMarasoiu Apr 08 '21 at 17:24