Reputation: 969
I using @Value("#{'${names}'.split(',')}") to loading List from properties file. But if the value of names in properties file is unset like this
names=
then Spring will initialize a list with size 1, not size 0, and the only element in this list is a empty string, that's weird.
I want to know is this a bug, or Im using it wrong? Im using spring 3.2.3 btw.
Thanks.
Upvotes: 1
Views: 1841
Reputation: 353
Other solution if you don't want to use external libraries is to use elvis expression.
Maybe not very elegant but works.
@Value("#{'${names}'.empty?(new java.util.ArrayList()):'${names}'.split(',')}")
Upvotes: 0
Reputation: 999
It's not bug of spring,is is a defect of method split
in String
class,example:
"".split(",");
the result length is 1,and contain a empty string;
Upvotes: 1