Setting null values:<property name="foo"><null/><property>
certain properties to be set just once—when the bean is created.this is inject by constructor.
there are two ways you can deal with ambiguities among constructor arguments: by index and by type.
<bean id="foo" class="com.springinaction.Foo">
<constructor-arg index="1">
<value>http://www.manning.com</value>
</constructor-arg>
<constructor-arg index="0">
<value>http://www.springinaction.com</value>
</constructor-arg>
</bean>
Which should you use—index or type? In the example above, it didn’t matter,because each argument had a distinct type. But
what if both arguments were Strings? If that’s the case, the type attribute won’t help you much and you must opt for the more
specific index attribute.
if you are creating a bean that has only one mandatory property (such as a DAO object as its DataSource), constructor
injection would probably be a good choice. On the other hand, if you have a bean that has multiple, optional properties (such
as the DataSource itself), setter injection would be more appropriate.
浙公网安备 33010602011771号