springboot中yml配置注入一般使用@Value注解可注入String类型数据,比如:

@Value("${config}")
String stringConfig;

即可注入属性,而注入list使用此方法则会报错提示Could not resolve placeholder xxx

注入list的正确方法

配置文件实例

list-config:
  config:
    - companyId
    - userId
    - originId

注入姿势

@ConfigurationProperties(prefix = "list-config")
@Component
@Setter
public class VisitorSourceController implements VisitorSourceApi {

    List<String> config;

}

注意:必须在类上添加Lombok的@Setter注解或者加上属性set方法,否则config属性会获取到null。


版权声明:本文为u011580177原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/u011580177/article/details/102844408