Since Spring 3.0, you can add a line like
<bean id="conversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean" />
to your applicationContext.xml
(or where you configure things).
As Dmitry Chornyi points out in a comment, Java based configuration looks like:
@Bean public ConversionService conversionService() {
return new DefaultConversionService();
}
This activates the new configuration service which supports converting String
to Collection
types.
If you do not activate this configuration service, Spring falls back on its legacy property editors as configuration services, which do not support this kind of conversion.
Converting to collections of other types works, too:
@Value("${my.list.of.ints}")
private List<Integer> myList
will work with a line like
my.list.of.ints= 1, 2, 3, 4
No problems with whitespace there, the ConversionServiceFactoryBean
takes care of it.
In a Spring application, you typically configure a ConversionService instance per Spring container (or ApplicationContext). That ConversionService will be picked up by Spring and then used whenever a type conversion needs to be performed by the framework. [...] If no ConversionService is registered with Spring, the original PropertyEditor-based system is used.