tags:

views:

49

answers:

2

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 following Java code:

ColorRegister.register(orange)
ColorRegister.register(yellow)
+1  A: 

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>
SingleShot
+3  A: 

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

ChssPly76