
Wiring Collections
The most commonly and widely used API of the java is collection. All the software uses some of the classes of collectgion to organize their objects in the application. The Spring also provides the means by which we can wire the collection to the properties of the other objects at the time of object creation. The following are the tags given by spring to wire various collection interfaces:-
- <list> Wiring a list of values, allowing duplicates.
- <set> Wiring a set of values, ensuring no duplicates
- <map> Wiring a collection of name-value pairs where name and value can be of any type
- <props> Wiring a collection of name-value pairs where the name and value are both Strings
Examples :- The following declarations will demonstrate the various collection wirings.
Lets take an example bean which has Set, Map and List collection properties:-
package com.visualbuilder.beans; import java.util.List; public class CollectionInjectionBean { |
<?xml version="1.0" encoding="UTF-8"?> <bean id="collectionExample" class="com.visualbuilder.beans.CollectionInjectionBean"> </beans> |
ColletionInjectionExample.java
package com.visualbuilder.example; import java.util.ArrayList; import org.springframework.context.ApplicationContext; import com.visualbuilder.beans.CollectionInjectionBean; public class ColletionInjectionExample { |
Output :-
Jun 1, 2008 2:08:13 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc: display name [org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc]; startup date [Sun Jun 01 14:08:13 IST 2008]; root of context hierarchy
Jun 1, 2008 2:08:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/visualbuilder/xml/spring-beans.xml]
Jun 1, 2008 2:08:13 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc]: org.springframework.beans.factory.support.DefaultListableBeanFactory@15e83f9
Jun 1, 2008 2:08:13 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15e83f9: defining beans [collectionExample]; root of factory hierarchy
Price of CAR is 100
Price of MOTORCYCLE is 200
Price of SCOOTER is 10
Java Discussion
- - Difference between BMT an
- - Replace getParameterValue
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin



