In my project i'm currently using application.yml
for configuration. Spring Initializr generate application.properties
? What are the Pro/Cons for each one?

- 8,411
- 24
- 67
- 76
4 Answers
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.

- 2,048
- 17
- 21
-
4Is YAML configuration format widely accepted across the whole SpringBoot world? When we come to a 3rd party library that provides only properties format configuration, is it easy to convert it to yaml format ourselves? – Bruce Sun Aug 19 '18 at 03:17
-
1@BruceSun It seems not so accepted, because official documentation uses it rarely, this uses .properties for instance: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html But my company's spring boot project template has yml... – masterxilo Nov 21 '18 at 09:34
-
4They are not just different data formats. YAML supports utf-8, application.properties doesn't – Nurlan Nov 29 '18 at 07:51
-
1Another question on this topic: When a library requires me to set a configuration to the application.yml file, can I assume that it can be loaded when I just set the property in the application.properties file? To be precise, is it the same mechanism to load a property for both files? – David Fariña Jun 20 '19 at 14:55
-
4also, what happens when my code base provides both an `application.yaml` as well as `application.properties`? can I just move the stuff in, say, the `.yaml` one into `.properties` (changing format as required) and expect things to continue to work the same way? – Erik Kaplun Jun 24 '19 at 12:35
As per my knowledge, these are at least some of the differences:
.properties
stores data in sequential format, whereas
.yml
stores data in hierarchical format..properties
supports only key-value pairs (basically string values), whereas
.yml
supports key-value pair, as well as map, list & scalar type values..properties
is specifically used by Java, whereas
.yml
can be used by other languages (eg Java, Python, ROR, etc).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.In Spring projects,
@PropertySource
annotation can only be used with.properties
.

- 139
- 2
- 4
- 13

- 2,273
- 1
- 18
- 28
-
1Good answer, just remarks about **point#2** `.properties file` : can supports key-value pair as well as map, list & scalar type values. + **point#3** `.properties file` can be used with any language – Ahmed Nabil Jul 20 '20 at 23:16
-
so we can have either application.yml or application.properties.. one is enough or both files required? – Stunner Jan 22 '21 at 03:51
-
so we can have either application.yml or application.properties.. one is enough or both files required? if we keep both files , what is the impact , which one will be picked up – Stunner Jan 22 '21 at 03:57
-
@Stunner It's completely depends on your requirements. But you can use both of them if they meet with your need. Example, I worked in one project and in that common properties like database configuration, cache configuration, mail configuration defined in application.properties and for device specific configuration we create different ymls. – Dhwanil Patel Jan 22 '21 at 04:25
-
so u mean to say , no matter how many properties file or yaml files declared or even the combination of both properties file and yaml file, the spring doesn't mind the number and loads all of them and both of them? – Stunner Jan 22 '21 at 04:33
-
No not exact that, Let's comes bit backward, Why properties or yml are used? Answer is for profiling and manage external properties. So not any professional developer create un-appropriate n number of files. In short have to create properties and yml file based on your number profile or some data which you want to pass as external data. – Dhwanil Patel Jan 22 '21 at 05:34
-
For second question, Spring not load all the profiles it load according to your need. Like active profile parameter or based on profile parameter you passed in environment variable or command line option. – Dhwanil Patel Jan 22 '21 at 05:36
-
I suppose you have bit confuse regarding properties or yml file define inside project and pass externally with command line param. Is it so? If you have some specific context then start chat or place question regarding that. Have a nice day :) – Dhwanil Patel Jan 22 '21 at 05:40
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

- 527
- 2
- 13
- 24
application.properties
It uses a simple key-value pair format.
Properties are defined using the key=value syntax.
Properties can be written in a single line or multiple lines, but each property is represented by a single key-value pair.
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/demo spring.datasource.username=root spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.show_sql=true
application.yml
It uses a YAML (YAML Ain’t Markup Language) format.
Properties are defined using indentation and hierarchical structure.
Properties can be written in a more structured manner using indentation and nesting.
YAML supports lists and maps, making it easier to represent complex configurations.
server: port: 8080
spring: datasource: password: root url: jdbc:mysql://localhost:3306/demo username: root jpa: hibernate: ddl-auto: update properties: hibernate: show_sql: true
Reference: spring boot properties vs. yaml

- 332
- 1
- 10
- 25