Search code examples
javaspringlistannotations

Spring @Value split empty string to a List


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.


Solution

  • 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;