The 30 second answer
Spring Boot loads both files rather than choosing just one. If the same property appears in both at the same location, application.properties takes precedence over application.yml. Properties that appear in only one file still contribute normally. That rule doesn't override the broader precedence rules for profiles or other configuration sources. I'd normally use one format consistently, as the documentation recommends, because mixing formats makes overrides harder to follow.
What the docs say: "If you have configuration files with both .properties and YAML format in the same location, .properties takes precedence."
Example:
# application.properties
server.port=9000# application.yml
server:
port: 8081
spring:
application:
name: ordersResult: server.port=9000 (from .properties) and spring.application.name=orders (only in YAML). Both files are active; only the overlapping key has a winner.
Why it works this way in the code. Spring Boot registers its file loaders in this order:
org.springframework.boot.env.PropertySourceLoader=\
org.springframework.boot.env.PropertiesPropertySourceLoader,\
org.springframework.boot.env.YamlPropertySourceLoaderspring.factories L8-L10. When building the references for one config name, the resolver goes through the loaders and their extensions and adds each with addFirst:
for (PropertySourceLoader propertySourceLoader : this.propertySourceLoaders) {
for (String extension : propertySourceLoader.getFileExtensions()) {
StandardConfigDataReference reference = new StandardConfigDataReference(configDataLocation, directory,
directory + name, profile, extension, propertySourceLoader);
if (!references.contains(reference)) {
references.addFirst(reference);
}
}
}StandardConfigDataLocationResolver.java L188-L199. The docs state the outcome: .properties takes precedence.
Location beats format. The format rule only applies within the same location. An application.yml in ./config/ outside the jar still beats an application.properties inside the jar, because location priority is checked first. Profile files also beat non-profile files regardless of format.
Other format differences:
- YAML supports multi-document files with
---;.propertiesuses#---. - YAML files cannot be loaded with
@PropertySource;.propertiescan. - YAML lists map to
my.list[0],my.list[1]keys.
Editor's note: pick one format per project. Two formats at once makes it easy to change a value in the wrong file and wonder why nothing happens.