I'd like to set default values for a list in a bean using annotations.
For example, if it's not a list you can do:
@Value("myValue")
String test;
But, in my case i want to give default values for a List of String.
List<String> tests;
In XML, it's something like that:
<bean id="beanId" class="class...">
<property name="tests">
<list>
<value>value 1</value>
<value>value 2</value>
<value>value 3</value>
</list>
</property>
</bean>
I wanted to know if there is an existing annotation, or if I have to create one ?
Thank you
@Value understands expression language, so you can use arbitrary method calls, although the syntax may get ugly, something like this:
@Value("#{T(java.util.Arrays).asList('Value 1','Value 2','Value 3')}")
Reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With