Saturday 5 September 2015

Inject Java Collection in Spring


<list> : This helps in wiring i.e. injecting a list of values, allowing duplicates.

<set> : This helps in wiring a set of values but without any duplicates.

<map> : This can be used to inject a collection of name-value pairs where name and value can be of any type.

<props> : This can be used to inject a collection of name-value pairs where the name and value are both Strings.

<beans>
       <!-- Definition for javaCollection -->
       <bean id="myCollection" class="com.MyCollection">
             
             <!-- java.util.List -->
              <property name="stdList">
                     <list>
                           <value>INDIA</value>
                           <value>Pakistan</value>
                           <value>USA</value>
                           <value>UK</value>
                     </list>
              </property>

             <!-- java.util.Set -->
              <property name="dataSet">
                     <set>
                           <value>INDIA</value>
                           <value>Pakistan</value>
                           <value>USA</value>
                           <value>UK</value>
                     </set>
              </property>

             <!-- java.util.Map -->
              <property name="stdMap">
                     <map>
                           <entry key="1" value="INDIA" />
                           <entry key="2" value="Pakistan" />
                           <entry key="3" value="USA" />
                           <entry key="4" value="UK" />
                     </map>
              </property>

             <!-- java.util.Properties -->
              <property name="loginProperies">
                     <props>
                           <prop key="admin">admin@gmail.com</prop>
                           <prop key="support">support@gmail.com</prop>
                     </props>
              </property>
       </bean>

</beans>


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...