Alesto
Alesto

Reputation: 689

Override property in YAML

I have a third party library, that is being configured with the important-config.yaml file.

prop1: value1
prop2: value2(need to override)
prop3: value3

To refer to it I have the next line in application.properties:

important-config=classpath:important-config.yaml

There is a property in yaml-file that depends on environment where app is running. So I need to override this property on startup. How can I do that?

Upvotes: 0

Views: 4009

Answers (1)

Oleg Cherednik
Oleg Cherednik

Reputation: 18245

I can see three suitable variants to solve it:

  1. Override properties directly in application.properties. I think that priority of is is higher that included congig (at least you could try to override property after you place important-config).
  2. You can override selected properties using command line directly java -jar app.jar --prop2="value2"
  3. Or override via system properties java -Dprop2="value2"-jar app.jar

Full informaiton you can find here http://www.baeldung.com/properties-with-spring

Absolute all properties are stored in Spring Environment object. You should pay attention on full variable name, because depending on other setting your prop2 could be store in xxx.yyy.prop2.

Upvotes: 1

Related Questions