I have the following:
List<Color> acceptableColors;
Using Spring, would it be best to instantiate this list this way:
<bean>
<list>
<value ref="orange" />
<value ref="yellow" />
....
</list>
</bean>
Or, is there a way to do a register scheme, where we use Spring to perform the followin开发者_StackOverflow中文版g Java code:
ColorRegister.register(orange)
ColorRegister.register(yellow)
Spring registers Color property editor by default, so you can do the following:
<util:list id="acceptableColors">
<value>255.127.0</value>
<value>255.255.0</value>
</util:list>
The above would create a List<Color>
instance. If you'd rather reference the colors by name you can write your own property editor
Without creating your own custom schema elements for Spring (which is possible and documented), this is probably the best you can do, using the util
schema/namespace:
<util:list id="acceptableColors">
<ref bean="orange"/>
<ref bean="yellow"/>
</util:list>
精彩评论