newbie: <lists> versus <util:list>

来源:互联网 发布:淘宝网页版回收站 编辑:程序博客网 时间:2024/06/06 09:54
I want to initialize a list property in proper Spring 2 fashion. Should I be using <util:list>? What's the syntax?

Here's the way I used to do it:
Code:
<bean id="snowWhite" class="Person">  <property name="friends">    <list>      <value>Sleepy</value>      <value>Grumpy</value>      <value>Bashful</value>    </list>  </property><bean>
The following works, but I'd rather not have to separate the list -- can't I embed the list right in the using bean, as in the example above?
Code:
<bean id="snowWhite" class="Person">  <property name="friends" ref="dwarfFriends"/><bean><util:list id="dwarfFriends">    <value>Sleepy</value>    <value>Grumpy</value>    <value>Bashful</value></util:list>

Thanks!


Hi Debe

You can (and should) keep on doing it the 'old' way.

The <util:list/> element is for defining a top level, shared List that you want to inject into numerous objects.

Cheers
Rick

0 0
原创粉丝点击