Spring Boot 的 application.yml 与 application.properties [英] application.yml vs application.properties for Spring Boot
问题描述
在我的项目中,我目前使用 application.yml
进行配置.Spring Initializr 生成application.properties
?每种方法的优缺点是什么?
In my project i'm currently using application.yml
for configuration. Spring Initializr generate application.properties
? What are the Pro/Cons for each one?
推荐答案
嗯,它们只是不同的数据格式.哪个更好,更容易阅读?这显然是主观的.这里是 一篇有用的博文.
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.
就 spring-boot
配置而言,请注意,使用 YAML
只有一个记录在案的缺点.根据 文档:
As far as spring-boot
configuration is concerned, note that there's only one documented shortcoming of using YAML
. Per the documentation:
YAML 文件无法通过 @PropertySource
注释加载.因此,如果您需要以这种方式加载值,则需要使用属性文件.
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.
这篇关于Spring Boot 的 application.yml 与 application.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!