Difference between YAML(.yml) and .properties file in Java SpringBoot
These are the files to have different configurations properties required to make the application up and run like to connect with the database what are the credentials, on which port the application will run, etc.
YAML (.yml) File: YAML is a configuration language. Languages like Python, Ruby, Java heavily use it for configuring the various properties while developing the applications.
If you have ever used Elastic Search instance and MongoDB database, both of these applications use YAML(.yml) as their default configuration format.
Example:
#.yml file some_key:value some_number:9 some_bool:true
Nesting: For nesting, the .yml file support hierarchy using spaces.
# .yml file
somemap:
key:value #use space not tab
number:9
#inline format
map2: {bool=true, date=2016-01-01}
Let’s define a list in such files: YAML as part of its specification supports the list.
#.propertes file # A List numbers[0] = one numbers[1] = two # Inline List numbers = one, two
.properties File: This file extension is used for the configuration application. These are used as the Property Resource Bundles files in technologies like Java, etc.
Example:
#.properties file some_key = value some_number = 9 some_bool = true
Nesting: For nesting, the .properties file support dot(.) notation. The inline format in the .yml file is very similar to JSON
#.properties file somemap.key = value somemap.number = 9 map2.bool = true map2.date = 2016-01-01
Let’s define a list in such files: .properties file doesn’t support list but spring uses an array as a convention to define the list in the .properties file.
#.yml file numbers: - one # use a dash follwed by space - two # Inline List numbers:[one, two]
Table of Difference:
| YAML(.yml) | .properties |
|---|---|
| Spec can be found here | It doesn’t really actually have a spec. The closest thing it has to a spec is actually the javadoc. |
| Human Readable (both do quite well in human readability) | Human Readable |
| Supports key/val, basically map, List and scalar types (int, string etc.) | Supports key/val, but doesn’t support values beyond the string |
| Its usage is quite prevalent in many languages like Python, Ruby, and Java | It is primarily used in java |
| Hierarchical Structure | Non-Hierarchical Structure |
| Spring Framework doesn’t support @PropertySources with .yml files | supports @PropertySources with .properties file |
| If you are using spring profiles, you can have multiple profiles in one single .yml file | Each profile need one separate .properties file |
| While retrieving the values from .yml file we get the value as whatever the respective type (int, string etc.) is in the configuration | While in case of the .properties files we get strings regardless of what the actual value type is in the configuration |
What should I use .properties or .yml file?
Strictly speaking, .yml file is advantageous over .properties file as it has type safety, hierarchy and supports list but if you are using spring, spring has a number of conventions as well as type conversions that allow you to get effectively all of these same features that YAML provides for you.
One advantage that you may see out of using the YAML(.yml) file is if you are using more than one application that read the same configuration file. you may see better support in other languages for YAML(.yml) as opposed to .properties.
Recommended Posts:
- Difference between SVG file and PNG file
- Java.util.Properties class in Java
- Difference between File and Folder
- Difference between File Transfer Protocol (FTP) and Secure File Transfer Protocol (SFTP)
- Properties contains(value) method in Java with Examples
- Properties get(key) method in Java with Examples
- Difference between Header file and Library
- Properties isEmpty() method in Java with Examples
- Properties containsKey(value) method in Java with Examples
- Properties keySet() method in Java with Examples
- Properties keys() method in Java with Examples
- Properties entrySet() method in Java with Examples
- Properties getProperty(key) method in Java with Examples
- Properties elements() method in Java with Examples
- Properties containsValue(value) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

