YAML vs Properties File: Which One to Choose?

Rakesh singhania
3 min readOct 16, 2023
Photo by Clem Onojeghuo on Unsplash

Choosing between YAML and properties files in a Spring Boot application depends on your preferences and the complexity of your configuration needs. Here are some considerations to help you decide:

YAML (YAML Ain’t Markup Language):

Advantages:

  1. Readability: YAML is often considered more human-readable and intuitive compared to properties files. It uses indentation and a clear structure, which can make it easier to understand complex configurations.
  2. Complex Configurations: If your application has a complex configuration with nested properties or lists, YAML can handle this more naturally than properties files.
  3. Profiles: YAML supports the use of profiles, which can be useful for managing configurations for different environments (e.g., development, production).
server:
port: 8080
address: 0.0.0.0
account:
delete:
gracePeriod: 30
public:
urls: /auth/token
format:
date-time: MM-dd-yyyy HH:mm:ss
date: MM-dd-yyyy
time: HH:mm:ss

Disadvantages:

  1. Whitespace Sensitivity: YAML is whitespace-sensitive, which means that incorrect indentation can lead to errors. This might be a consideration if your team is not familiar with YAML.

Properties Files (.properties):

Advantages

  1. Simplicity: Properties files are very straightforward and easy to work with. They consist of key-value pairs without any complex syntax.
  2. Historical Usage: Properties files have been used for a long time in Java applications, so they might be more familiar to developers who have worked with Java for a while.
# .properties file

spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000

Disadvantages

  1. Limited Structure: Properties files have a flat structure and do not support nested properties or lists. This can make them less suitable for complex configurations.

--

--

Rakesh singhania

As a student of technology, each day I take a single step forward on the path of learning.