---
title: "springboot map<String,MyObject> config  application.yml "
author: "e_e"
date: "2019-01-25T23:34:25Z"
tags: []
categories: ["企业架构"]
slug: "springboot-map-string-myobject-config-application-yml"
draft: false
lastmod: "2019-01-25T23:34:25Z"
id: 2437081
url: "https://e-e.iteye.com/blog/2437081"
---

### 参考官网：https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

### 章节：  24.8.3 Merging Complex Types

application.yml

```
element-datasource:
  config:
    service1:
      url:
      method:
      content-type:
    service2:
      url:
      method:
      content-type:
```

 

 

```
@Component
@Configuration
@ConfigurationProperties("element-datasource")
@Data
public class ElementDatasourceConfig {

    private final Map<String , ExternalDatasourceProperties> config = new HashMap<>();

@Data
public static class ExternalDatasourceProperties {
        private String url;
        private String method;
        private String contentType;
}

}
```