<property name="listOfShape"> <list> <value>Triangle</value> <value>Circle</value> <value>Rectangle</value> <value>Square</value> </list> </property>
<property name="listOfShape"> <list> <value>Triangle</value> <value>Circle</value> <ref bean="rectangle"></ref> <bean class="com.dineshonjava.sdnext.Square"> <property name="width" value="20"></property> </bean> </list> </property>
<property name="setOfShape"> <set> <value>Triangle</value> <value>Circle</value> <value>Rectangle</value> <value>Square</value> </set> </property>
<property name="setOfShape"> <set> <value>Triangle</value> <value>Circle</value> <ref bean="rectangle"></ref> <bean class="com.dineshonjava.sdnext.Square"> <property name="width" value="20"></property> </bean> </set> </property>
<property name="mapOfShape"> <map> <entry key="1" value="Triangle"> <entry key="2" value="Circle"> <entry key="3" value="Rectangle"> <entry key="4" value="Square"> </entry></entry></entry></entry> </map> </property>
<property name="mapOfShape"> <map> <entry key="1" value="Triangle"></entry> <entry key="2" value="Circle"></entry> <entry key="3" value-ref="rectangle"></entry> <entry key="4"> <bean class="com.dineshonjava.sdnext.Square"> <property name="width" value="20"></property> </bean> </entry> </map> </property>
<property name="proprtyOfShape"> <props> <prop key="triangle">Triangle</prop> <prop key="circle">Circle</prop> <prop key="rectangle">Rectangle</prop> <prop key="sqare">Square</prop> </props> </property>
package com.dineshonjava.sdnext.injectingCollection; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; public class ShapeCollection { private List<string> shapeOfList; private Set<string> shapeOfSet; private Map<string string=""> shapeOfMap; private Properties shapeOfProperties; /** * @param shapeOfList the shapeOfList to set */ public void setShapeOfList(List<string> shapeOfList) { this.shapeOfList = shapeOfList; } /** * @param shapeOfSet the shapeOfSet to set */ public void setShapeOfSet(Set<string> shapeOfSet) { this.shapeOfSet = shapeOfSet; } /** * @param shapeOfMap the shapeOfMap to set */ public void setShapeOfMap(Map<string string=""> shapeOfMap) { this.shapeOfMap = shapeOfMap; } /** * @param shapeOfProperties the shapeOfProperties to set */ public void setShapeOfProperties(Properties shapeOfProperties) { this.shapeOfProperties = shapeOfProperties; } public String toString() { return "List Elements :" + shapeOfList+"\nSet Elements :" + shapeOfSet+"\n" + "Map Elements :" + shapeOfMap+"\nProperty Elements :" + shapeOfProperties; } }
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean class="com.dineshonjava.sdnext.injectingCollection.ShapeCollection" id="shapeCollection"> <property name="shapeOfList"> <list> <value>Triangle</value> <value>Circle</value> <value>Circle</value> <value>Rectangle</value> </list> </property> <property name="shapeOfSet"> <set> <value>Triangle</value> <value>Circle</value> <value>Circle</value> <value>Rectangle</value> </set> </property> <property name="shapeOfMap"> <map> <entry key="1" value="Triangle"> <entry key="2" value="Circle"> <entry key="3" value="Circle"> <entry key="4" value="Rectangle"> </entry></entry></entry></entry></map> </property> <property name="shapeOfProperties"> <props> <prop key="triangle">Triangle</prop> <prop key="circle1">Circle</prop> <prop key="circle2">Circle</prop> <prop key="rectangle">Rectangle</prop> </props> </property> </bean> </beans>DrawingApp.java
package com.dineshonjava.sdnext.injectingCollection.tutorial; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.dineshonjava.sdnext.injectingCollection.ShapeCollection; /** * @author Dinesh Rajput * */ public class DrawingApp { /** * @param args */ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); ShapeCollection shapeCollection = (ShapeCollection) context.getBean("shapeCollection"); System.out.println(shapeCollection); } }
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean class="com.dineshonjava.sdnext.injectCollection.Triangle" id="triangle"> <property name="height" value="30"></property> <property name="type" value="Eqiletral"></property> </bean> <bean class="com.dineshonjava.sdnext.injectingCollection.ShapeCollection" id="shapeCollection"> <property name="shapeOfList"> <list> <value>Circle</value> <value>Circle</value> <ref bean="triangle"></ref> <bean class="com.dineshonjava.sdnext.injectCollection.Rectangle"> <property name="height" value="30"></property> <property name="width" value="50"></property> </bean> </list> </property> <property name="shapeOfSet"> <set> <value>Circle</value> <value>Circle</value> <ref bean="triangle"></ref> <bean class="com.dineshonjava.sdnext.injectCollection.Rectangle"> <property name="height" value="30"></property> <property name="width" value="50"></property> </bean> </set> </property> <property name="shapeOfMap"> <map> <entry key="2" value="Circle"></entry> <entry key="3" value="Circle"></entry> <entry key="1" ref-value="triangle"></entry> <entry key="4"> <bean class="com.dineshonjava.sdnext.injectCollection.Rectangle"> <property name="height" value="30"></property> <property name="width" value="50"></property> </bean> </entry> </map> </property> <property name="shapeOfProperties"> <props> <prop key="triangle">Triangle</prop> <prop key="circle1">Circle</prop> <prop key="circle2">Circle</prop> <prop key="rectangle">Rectangle</prop> </props> </property> </bean> </beans>
Labels: Spring3.0