How does Spring Boot application with application.yml behave for when dependency also has an application.yml file

Viewed 1140

What happens if, for a spring boot application. The application has an application.yml defined and also one of the dependencies of the application has an application.yml too.

Will spring merge both the properties, Take the final and boot up? In case spring merges both the properties, How will common properties be handled?

1 Answers

The two will get merged.

  • Properties with the same name: the values in your application's application.yaml will override the values from the dependencies application.yaml.
  • Properties which are not overwritten (defined in both yaml) will be taken as they are. Everything which you do not include in your application's application.yaml, will default to the value defined in the dependency application.yaml.

Example:

application.yaml in dependency project:

something:
  first: value1
  second: value2
otherthing:
  third: value3

application.yaml in my application:

something:
  first: myvalue1 // this will override value1
mysetup:
  fourth: myvalue2

the values not specified in myapplication.yaml will be taken from dependency.yaml

Source: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

Related