Load multiple yaml file with same root key in spring boot

本秂侑毒 提交于 2021-02-11 13:01:45

问题


I'm looking for a solution in spring boot where I can maintain same root key in multiple files and load it to a POJO.

application-profile-1.yml
active:
  configuration:
  - name: abc
  ....... (1000 lines in config)
application-profile-2.yml
active:
  configuration:
  - name: xyz
  ....... (900 lines in config)
application-profile-3.yml
active:
  configuration:
  - name: abc
  ....... (700 lines in config)
application.yml
spring.profiles.include: profile-1,profile-2,profile-3
@ConfigurationProperties(prefix = "active")
public class ActiveData {
   private List<Configuration> channels = null;
}

After autowiring when I try to access configuration I see null.

Service {
    @Autowired
    private ActiveData activeData;

    serviceMethod() {
        activeData.configuration(); --> is coming as null
    }

}

来源:https://stackoverflow.com/questions/64610099/load-multiple-yaml-file-with-same-root-key-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!