application.properties:
my.list=1,2,3,4
I want to inject this as a List
into a @Value
field:
@Value("${my.list}")
List<Integer> list;
On the net I found that the following bean has to be registered for this to work:
@Bean
public ConversionService conversionService() {
return new DefaultConversionService();
}
Result:
org.springframework.beans.TypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.util.List];
Caused by: java.lang.NumberFormatException: For input string: "1,2,3,4"
Somehow spring
is not trying to parse this as a list. Why?
I know it is possible using spEL with @Value("#{'${my.list}'.split(',')}")
, but I'm explicit looking in a solution without spel conversation.