将PropertyPlaceholderConfigurer与列表一起使用 [英] Use PropertyPlaceholderConfigurer with List
本文介绍了将PropertyPlaceholderConfigurer与列表一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PropertyPlaceholderConfigurer来映射属性文件中的字符串值,并且工作正常.
I am using PropertyPlaceholderConfigurer to map String values from properties file and it works ok.
我的问题是,是否可以在属性文件中设置以下内容: myList = A,B,C
My question is if I can set something the this in my property file: myList=A,B,C
然后将其映射到列表
@Value("${myList}")
private List<String> myList;
当我尝试将所有值放在列表的一个位置时. 有什么办法告诉它用,"将其分成一个列表吗?
When I try that it puts all the values in one place of the list. Is there any way to tell it to break this to a list by ","?
推荐答案
使用Spring Expression语言:
Using Spring Expression language:
@Value("#{'${myList}'.split(',')}")
private List<String> myList;
如果属性文件中的myList=A,B,C
,将导致myList
(在代码中),其值分别为A
,B
和C
If myList=A,B,C
in property file this will result in myList
(in the code) with the values A
, B
and C
这篇关于将PropertyPlaceholderConfigurer与列表一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文