Spring Boot: read list from yaml using @Value or @ConfigurationProperties

后端 未结 4 851
旧时难觅i
旧时难觅i 2020-12-28 08:25

I want to read a list of hosts from a yaml file (application.yml), the file looks like this:

cors:
    hosts:
        allow: 
            - http://foo1/
             


        
4条回答
  •  情书的邮戳
    2020-12-28 08:53

    use comma separated values in application.yml

    corsHostsAllow: http://foo1/, http://foo2/, http://foo3/
    

    java code for access

    @Value("${corsHostsAllow}")    
    String[] corsHostsAllow
    

    I tried and succeeded ;)

提交回复
热议问题