Java 弹簧,具有分隔符时的属性值

Java 弹簧,具有分隔符时的属性值,java,spring,properties,inject,Java,Spring,Properties,Inject,我正在加载带有的属性文件 @PropertySource("classpath:propFile.properties") 在此属性文件中,我有以下条目: list.of.stg=a,b,c 此外,我确实: @Value("${list.of.stg}")public void setSomeList(...){in the method, the parameter has only the value a!!!} 谢谢大家! 当属性值作为String传入时,您必须使用String#split


我正在加载带有的属性文件

@PropertySource("classpath:propFile.properties")
在此属性文件中,我有以下条目:

list.of.stg=a,b,c
此外,我确实:

@Value("${list.of.stg}")public void setSomeList(...)
{in the method, the parameter has only the value a!!!}

谢谢大家!

当属性值作为
String
传入时,您必须使用
String#split
,但您可以结合使用:

@Value(“#{${list.of.stg}”.split(',')}”)
公共无效集合列表(列表){
this.myList=list;
}
或者简单地在类成员变量上

@Value("#{'${list.of.stg}'.split(',')}") 
private List<String> myList;
@Value(“#{${list.of.stg}”.split(',')}”)
私人名单;

与使用
@PropertySource
注释时一样,不要忘记创建
propertyplaceholderconfigure
@Bean
以加载必要的属性文件


相关:

当属性值作为
字符串传入时,您必须使用
String 35; split
,但您可以结合使用:

@Value(“#{${list.of.stg}”.split(',')}”)
公共无效集合列表(列表){
this.myList=list;
}
或者简单地在类成员变量上

@Value("#{'${list.of.stg}'.split(',')}") 
private List<String> myList;
@Value(“#{${list.of.stg}”.split(',')}”)
私人名单;

与使用
@PropertySource
注释时一样,不要忘记创建
propertyplaceholderconfigure
@Bean
以加载必要的属性文件

相关:

尝试

@Value("#{T(org.springframework.util.StringUtils).commaDelimitedListToStringArray(environment['list.of.stg'])}")
试一试

@Value("#{T(org.springframework.util.StringUtils).commaDelimitedListToStringArray(environment['list.of.stg'])}")

谢谢你的回答——确实有效。然而,该网站只允许我“勾选”一个答案。我选择了Jose Beuca给出的答案,因为你已经有很多分数了:)对不起!:0谢谢你的回答-确实有效。然而,该网站只允许我“勾选”一个答案。我选择了Jose Beuca给出的答案,因为你已经有很多分数了:)对不起!:0