I want this property mapped on application.properties
my.list=a;b;c
converted to a List (or eventually a String[]); there are 2 requirements;
- my.list is separated by ; char
- my.list could be empty
I tried with:
@Value("#{T(java.util.Arrays).asList('${my.list:}'.split(';'))}")
but it doesn't work as expected, as passing multiple values convert the list with a single element "a,b,c".
PS I already know there is a very similare SO question, however the solution was not tested with separator different from ','.
CodePudding user response:
Just use
@Value("#{'${my.list:}'.split(';')}#{T(java.util.Collections).emptyList()}")
List<String> listValue;