Mapping list in Yaml to list of objects in Spring Boot

后端 未结 6 831
暖寄归人
暖寄归人 2020-11-29 03:52

In my Spring Boot app I have application.yaml configuration file with following content. I want to have it injected as a Configuration object with list of channel configurat

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 04:28

    • You don't need constructors
    • You don't need to annotate inner classes
    • RefreshScope have some problems when using with @Configuration. Please see this github issue

    Change your class like this:

    @ConfigurationProperties(prefix = "available-payment-channels-list")
    @Configuration
    public class AvailableChannelsConfiguration {
    
        private String xyz;
        private List channelConfigurations;
    
        // getters, setters
    
        public static class ChannelConfiguration {
            private String name;
            private String companyBankAccount;
    
            // getters, setters
        }
    
    }
    

提交回复
热议问题