springboot配置文件给集合list、map类型赋值

417 阅读1分钟

MAP类型

  • 实体
@Component
@ConfigurationProperties("no-oauth")
public class NoOauthGatewayProperties {

    private Map<String,List<String>> url = new HashMap<>();

    public Map<String, List<String>> getUrl() {
        return url;
    }

    public void setUrl(Map<String, List<String>> url) {
        this.url = url;
    }
}
  • 配置文件application.yml
no-oauth:
  url:
    app-lebilin:
      - /rest/lbl/app/user/register
      - /rest/lbl/app/user/login
      - /rest/lbl/app/user/resetPassword
      - /rest/lbl/app/user/encryptRegister

LIST类型

在properties文件中使用[]来定位列表类型,比如:

no-oauth.url[0]=/a/b

no-oauth.url[1]=/a/c

也支持使用逗号分割的配置方式,上面与下面的配置是等价的:

no-oauth.url=/a/b,/a/c

而在yaml文件中使用可以使用如下配置:

no-oauth:
    url:
      - /a/b
      - /a/c

也支持逗号分割的方式:

no-oauth:
    url: /a/b, /a/c