用于 Spring Boot 的 application.yml 与 application.properties [英] application.yml vs application.properties for Spring Boot

查看:27
本文介绍了用于 Spring Boot 的 application.yml 与 application.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我目前正在使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆