Using YAML Instead of Properties
YAML是JSON的超集,因此是用于指定分层配置数据的便捷格式。只要在类路径中有SnakeYAML库(SnakeYAML是生成和解析YAML的第三方工具),SpringApplication
类就会自动支持YAML
替代properties
。
如果你使用“Starters”
,spring-boot-starter
自动提供SnakeYAML。
environments:
dev:
url: https://dev.example.com
name: Developer Setup
prod:
url: https://another.example.com
name: My Cool App
转换为以下属性:
environments.dev.url=https://dev.example.com
environments.dev.name=Developer Setup
environments.prod.url=https://another.example.com
environments.prod.name=My Cool App
YAML列表可以转换为带[index]的属性键
my:
servers:
- dev.example.com
- another.example.com
转换为以下属性:
my.servers[0]=dev.example.com
my.servers[1]=another.example.com