Spring Boot配置文件yml自定义数组或List集合

自定义List集合

首先在application.yml文件中配置

1
2
3
4
5
6
7
email:
mailList[0]:
username: xxx@xxx.com
password: axxx
mailList[1]:
username: xxx@xxx.com
password: bxxx

然后配置接受类

1
2
3
4
5
6
@Data
@Configuration
@ConfigurationProperties("email")
public class EmailConfig {
private List<MailInfo> mailList; //注意字段名称保持一致
}

MailInfo类的内容是

1
2
3
4
5
@Data
public class MailInfo {
private String username;
private String password;
}

自定义数组

首先在application.yml文件中配置

1
2
3
path:
ignored-token-path: /base/xx/login, /home/**
ignored-role-path: /base/xx/logout, /base/xx/menu

然和配置接受类

1
2
3
4
5
6
7
@Data
@Configuration
@ConfigurationProperties("path")
public class PathConfig {
private String[] ignoredTokenPath;
private String[] ignoredRolePath;
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :