Springboot配置文件中配置List集合

时间:2025-02-13 17:21:03

Springboot的配置文件分为两种:

一种为properties文件;

另一种为yml文件。

本文以yml的配置来说明。

在开发过程中遇到需要给特定的几个部门进行数据推送,而且设置的部门需要可配置,在这个需求中就可以使用在配置文件中配置集合,具体在yml中的配置如下:

mes:
  #  接口地址
  url: http://localhost:9006/bomService/receivePlanTask
  # 部门列表   在列表的进行推送,不在列表的不进行推送
  deptList:
    - '6010201'
    - '6010202'
    - '6010203'

集合和对象的读取方式一样,也是使用 @ConfigurationProperties 来读取的,具体实现如下:

import ;

import ;

import ;
import ;

/**
 * 描述: .
 *
 * @author fucc
 * @version 2023.05.16 2023/5/16 19:04
 */
@Data
@Component
@ConfigurationProperties(prefix = "mes")
public class MesConfig {

    private String url;

    private List<String> deptList;
}