将嵌套的yaml列表映射到Spring boot Config

时间:2016-07-29 14:00:46

标签: java spring spring-boot yaml

我正在使用spring cloud配置服务器/客户端获取一些集中式yaml配置,如下所示:

app:
      workflows:
        - name: name1
          tag : tag1 
          producer:
              acks: all
              retries: 0
          consumer: 
              id: 1
              timeout: 1
        - name: name2
          tag : tag2 
          producer:
              acks: xyz
              retries: 1
          consumer: 
              id: 2
              timeout: 3

我在获取嵌套的生产者和消费者元素时遇到问题,他们在Config对象中显示为null。这是目前的能力:

@ConfigurationProperties(prefix="app")
public class MSConfiguration {

    private List<Config> workflows = new ArrayList<>();


    public List<Config> getWorkflows() {
        return workflows;
    }



    public static class Config {
        private String name;
        private String tag;
        private Producer producer;
        private Consumer consumer;

        //getters and setters here

    }

    @ConfigurationProperties(prefix="producer")
    public static class Producer {
        private String acks;
        private String retries;

        //getters and setters here

    }

    @ConfigurationProperties(prefix="consumer")
    public static class Consumer {
        private String id;
        private String timeout;

        //getters and setters here
    }

0 个答案:

没有答案