Wuaner Wuaner - 2 years ago 132
Java Question

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


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.


Answer Source

It's not bug of spring,is is a defect of method split in String class,example:


the result length is 1,and contain a empty string;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download