Spring – Collection DI Parameters | Code Factory


Donate : Link

Medium Blog : Link

Applications : Link

This image has an empty alt attribute; its file name is image-1.png

Spring Tutorial Index Page: Link

  • For List, Set, Map collection we use <list>, <set>, and <map> tags.
  • We have to define List, Set, Map interface to use these tags.
  • * Default it will create ArrayList for list, LinkedHashSet for set and LinkedHashMap for map tag.
<bean id="" class="">
	<property name="">
		<list>
			<value></value>
		</list>
	<property>
</bean>
  • If we declare implemented classes like Vector, TreeSet, HashTable then we can’t able to assign values using these tags.
<bean id="" class="">
	<property name="">
		<util:list list-class="java.util.Vector">
			<value></value>
		</util:list>
	<property>
	<property name="">
		<util:set set-class="java.util.TreeSet">
			<value></value>
		</util:set>
	<property>
	<property name="">
		<util:map map-class="java.util.HashTable">
			<entry key="IND" value="Delhi" />
		</util:map>
	<property>
</bean>
  • For above scenario we have to use xml schema instead of going through dtd based configuration. Through dtd it is not possible.
  • For Property, inside dtd based configuration we can pass required key-value pairs.
<bean id="" class="">
	<property name="">
		<props>
			<prop key="fname">ABC</prop>
		</props>
	<property>
</bean>
  • For Map we use <entry> tag but for Property we use <props> tag.
  • In case of simple dtd based configuration it is not possible to read external property data. If you want to read external property files data then you have to go through namespace. You have to use util namespace here. Xml schemas we have to use instead of dtd based configuration.
<beans xmlns="bean-namespace" xmlns:util="util-namespace">
	<bean id="" class="">
		<property name="">
			<util:property location="classpath:resources/Drivers.properties">
		<property>
	</bean>
</beans>
  1. Spring – Default Collection DI Parameters
  2. Spring – Required Collection DI Parameters
  3. Spring – java.util.Properties DI Parameters
  4. Spring – Properties File DI Parameters
  5. Spring – Properties File Data DI Parameters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s