In my project i'm currently using application.yml
for configuration. Spring Initializr generate application.properties
? What are the Pro/Cons for each one?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With