application.yml vs application.properties for Spring Boot

One notable difference is how the properties are represented in each file. YAML files may use consistent spaces to denote hierarchy whereas properties file may use = to denote property values.

For ex.

Lists are represented hierarchically in YAML:

headers:

  - user-agent
  - x-wag-diagonalsize

Lists may be represented as inline list (separated by commas) in a properties file:

headers = user-agent, x-wag-diagonalsize

Another difference is we can add multiple configuration files into single yaml file.

For ex., we can add application.yaml(application specific properties) and bootstrap.yaml(server specific properties) into single config.yaml file


Well, they are just different data formats. Which one's nicer and easier to read? That's obviously subjective. Here's a useful blog post.

As far as spring-boot configuration is concerned, note that there's only one documented shortcoming of using YAML. Per the documentation:

YAML files can’t be loaded via the @PropertySource annotation. So in the case that you need to load values that way, you need to use a properties file.


As per my knowledge, these are at least some of the differences:

  1. .properties stores data in sequential format, whereas
    .yml stores data in hierarchical format.

  2. .properties supports only key-value pairs (basically string values), whereas
    .yml supports key-value pair, as well as map, list & scalar type values.

  3. .properties is specifically used by Java, whereas
    .yml can be used by other languages (eg Java, Python, ROR, etc).

  4. When managing multiple configuration profiles, then:
    .properties requires you to create .properties file per every profile, whereas in
    .yml you can create a section for each specific profile inside a single .yml file.

  5. In Spring projects, @PropertySource annotation can only be used with .properties.