【问题标题】:Spring reading properties from application.properties file with wildcard使用通配符从 application.properties 文件中读取属性
【发布时间】:2017-06-26 01:39:32
【问题描述】:

我想在 spring 中使用通配符从 application.properties 中读取一组属性。

例如我有这个属性:

file.processing.xpath.query.1=query1
file.processing.xpath.query.2=query2

然后我想在这样的数组或列表中获取属性

 @Value("${file.processing.xpath.query.*}")
    private String[] xpathQuery;

有没有办法做到这一点?

当我尝试这样做时,我收到一个异常

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'file.processing.xpath.query' in string value "${file.processing.xpath.query.*}"

【问题讨论】:

    标签: java spring properties


    【解决方案1】:

    你必须像这样定义你的属性:

    file.processing.xpath.query=query1,query2,query3
    

    然后使用:

    @Value("${file.processing.xpath.query}")
        private String[] xpathQuery;
    

    【讨论】:

    • 以这种方式进行测试有什么运气吗?
    猜你喜欢
    • 2015-10-08
    • 2016-03-16
    • 1970-01-01
    • 2020-03-26
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    相关资源
    最近更新 更多