> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/24.-externalized-configuration/24.6.-using-yaml-instead-of-properties/24.6.5.-merging-yaml-lists.md).

# 24.6.5. 合并YAML列表

正如[之前](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-loading-yaml)展示的，所有YAML最终都转换为properties，在通过一个profile覆盖"list"属性时这个过程可能不够直观（counter intuitive）。例如，假设有一个`MyPojo`对象，默认它的`name`和`description`属性都为`null`。下面的例子从`AcmeProperties`暴露一个`MyPojo`对象列表（list）：

```java
@ConfigurationProperties("acme")
public class AcmeProperties {

    private final List<MyPojo> list = new ArrayList<>();

    public List<MyPojo> getList() {
        return this.list;
    }

}
```

考虑如下配置：

```
acme:
  list:
    - name: my name
      description: my description
---
spring:
  profiles: dev
acme:
  list:
    - name: my another name
```

如果`dev` profile没有激活，`AcmeProperties.list`将包括一个如之前定义的`MyPojo`实体。即使`dev`生效，该`list`仍旧只包含一个实体（`name`值为`my another name`，`description`值为`null`）。此配置不会向该列表添加第二个`MyPojo`实例，也不会对该项进行合并。

当一个集合定义在多个profiles时，只使用优先级最高的。考虑下面的例子：

```
acme:
  list:
    - name: my name
      description: my description
    - name: another name
      description: another description
---
spring:
  profiles: dev
acme:
  list:
     - name: my another name
```

在之前的示例中，如果`dev` profile激活，`AcmeProperties.list`将包含一个`MyPojo`实体（`name`值为`my another name`，`description`值为`null`）。
