开发者

Spring (Java) - register vs list

开发者 https://www.devze.com 2022-12-09 15:52 出处:网络
I have the following: List<Color> acceptableColors; Using Spring, would it be best to instantiate this list this way:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消