Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

使用Springboot yml配置文件的问题 Could not resolve placeholder

在springboot中使用application.yml配置文件时,通过@Value加载配置参数,普通参数一切ok,只要涉及数组,就提示Could not resolve placeholder 'XXX' in value "${XXX}",请教一下应该从哪里查问题?

t1:
  tta: 1234
  list:
    - 123
    - 123
    - 123
    - 123
devicelist:
  - {cameraIp: '10.10.10.36', motoIp: '10.10.10.114'}
  - {cameraIp: '10.10.10.35', motoIp: '10.10.10.113'}

以上内容t1.tta可获取,但 t1.list、devicelist都会报错
springboot试过2.3.3、2.3.5、2.4.0 都不行
开发环境是idea 2020.03
以上内容在yaml在线校验通过,没有问题
以下是配置参数注解

    @Value("${t1.tta}")
    private String tta;
    @Value("${devicelist}")
    private List<Map<String,String>> settingsDevices;
    @Value("${t1.list}")
    private List<String> list;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@Value 只支持基本类型,数组(何况你这也不是数组,是列表)需要你自己实现。

可以参考这篇来实现:https://www.cnblogs.com/levi1...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...