Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PropertyPlaceholderConfigurer with List

Tags:

spring

I am using PropertyPlaceholderConfigurer to map String values from properties file and it works ok.

My question is if I can set something the this in my property file: myList=A,B,C

And then map it to a list

@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 ","?

like image 925
Joly Avatar asked Mar 06 '12 13:03

Joly


1 Answers

Using Spring Expression language:

 @Value("#{'${myList}'.split(',')}") 
 private List<String> myList;

If myList=A,B,C in property file this will result in myList (in the code) with the values A, B and C

like image 120
Wilhelm Kleu Avatar answered Oct 04 '22 06:10

Wilhelm Kleu