Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application.yml vs application.properties for Spring Boot

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

like image 204
cupakob Avatar asked Nov 23 '17 20:11

cupakob


People also ask

Which is better application yml or application properties?

YAML files are more clear and human-readable in comparison to properties files and also provide several unique and useful feature for us. YAML supports Maps, lists, and scalar types.

Is application yml same as application properties?

Unlike properties files, YAML supports multi-document files by design, and this way, we can store multiple profiles in the same file no matter which version of Spring Boot we use. Note: We usually don't want to include both the standard application.

Which is better to configure a spring boot project properties or YAML?

YAML is a human-friendly notation used in configuration files. Why would we prefer this data serialization over the properties file in Spring Boot? Besides readability and reduction of repetition, YAML is the perfect language to write Configuration as Code for the deployments.

How do I use YAML instead of properties in spring boot?

Since I use spring-boot-starter the SnakeYAML library is already in the classpath, and SpringApplication should use the YAML version automatically. The SpringApplication class will automatically support YAML as an alternative to properties whenever you have the SnakeYAML library on your classpath.


1 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.

like image 189
The_Tourist Avatar answered Oct 04 '22 18:10

The_Tourist