Spring @Value empty list as default

Roby Rodriguez :

Is there a way to set an empty list as default value for a property in Spring, something like:

@Value("${my.list.of.strings :" + new ArrayList<>() + "}")
private List<String> myList;

Obviously not new ArrayList, but I need an empty list there instead.

Roby Rodriguez :

After taking a look at SpEL specification and combined with @javaguy's answer I came up with this:

@Value("${my.list.of.strings:}#{T(java.util.Collections).emptyList()}")
private List<String> myList;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=452569&siteId=1