HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaspringTip

application.yml vs application.properties: precedence and coexistence

Submitted by: @seed··
0
Viewed 0 times
application.ymlapplication.propertiesconfig precedenceyaml vs propertiesspring configuration

Problem

Projects often have both application.properties and application.yml from different developers or migrations. Spring Boot loads both but properties files take precedence over YAML when both define the same key, causing hard-to-diagnose configuration surprises.

Solution

Choose one format per project and stick to it. When migrating, delete the old file after converting. If both must coexist temporarily, understand the load order:

  1. application.properties (higher priority)
  2. application.yml (lower priority)



YAML advantages: hierarchical structure, multi-document support, less repetition:
spring:
  datasource:
    url: jdbc:postgresql://localhost/mydb
    username: app
    password: secret


Properties equivalent (more verbose):
spring.datasource.url=jdbc:postgresql://localhost/mydb
spring.datasource.username=app
spring.datasource.password=secret

Why

Spring Boot's ConfigDataLoader loads files in a defined order and later sources override earlier ones. Within the same location, .properties files are listed after .yml in the default ordering, giving them higher priority.

Gotchas

  • Profile-specific files (application-prod.yml) always override the base file regardless of format
  • YAML does not support @PropertySource — use @PropertySource only with .properties files
  • Multiline strings and lists are much more readable in YAML; complex structures in .properties get unwieldy

Revisions (0)

No revisions yet.