YAML 和 properties 的对应关系

  1. 基本元素表示,包含 String 和 char, boolean, byte, short, int, long, float, double 及其对应包装类
# yaml
spring:
	yaml:
		property: value
# properties 
spring.yaml.property = value
  1. Collection (list/set/Array) 表示
# yaml 风格
collectionOne: ["a","b","c"]

collectionTwo:
	- zengxu
  - theday

# properties 风格
collectionOne[0]=a
collectionOne[0]=b
collectionOne[0]=c

collectionTwo[0]=zengxu
collectionTwo[1]=theday
  1. Map 表示
# yaml 风格
map:
  key1: value1
	key2: value2
  mapInMap:
    key3: value3
	  key4: value4
# properties 风格
map.key1=value1
map.key2=value2
map.mapInMap.key3=value3
map.mapInMap.key4=value4
  1. POJO 表示
# yaml
pojo:
	name: name
  desc: desc
pojoList:
  - name: zengxu
    desc: nextday
  - name: zeng
    desc: theday
# properties
pojo.name=name
pojo.desc=desc

pojoList[0].name=zengxu
pojoList[0].desc=nextday
pojoList[1].name=zeng
pojoList[1].desc=theday

@ConfigurationProperties 和 @Value 差异

@Value , ${...} 由 PropertySourcesPlaceholderConfigurer 负责解析

@ConfigurationProperties 由 ConfigurationPropertiesBindingPostProcessor

SpringBoot 文档列出的差异

差异对比

Relaxed binding