tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > Core > Typed List Injection

Typed List Injection 

Spring Inversion of Control (IoC) also known as Dependency Injection (DI) is a process by which objects define their dependencies with collaborating objects. The following example shows typed list injection.

File Name  :  
/SpringCore001/conf/typed_collections/typed_list_inj.xml 

File Name  :  
com/bethecoder/tutorials/spring3/basic/ComplexTypedBean.java 
   
package com.bethecoder.tutorials.spring3.basic;

public class ComplexTypedBean {

  private java.util.Properties simpleProps;
  private java.util.List<Double> simpleList;
  private java.util.Map<String, Float> simpleMap;
  private java.util.Set<Long> simpleSet;
  
  public java.util.Properties getSimpleProps() {
    return simpleProps;
  }
  public void setSimpleProps(java.util.Properties simpleProps) {
    this.simpleProps = simpleProps;
  }
  public java.util.List<Double> getSimpleList() {
    return simpleList;
  }
  public void setSimpleList(java.util.List<Double> simpleList) {
    this.simpleList = simpleList;
  }
  public java.util.Map<String, Float> getSimpleMap() {
    return simpleMap;
  }
  public void setSimpleMap(java.util.Map<String, Float> simpleMap) {
    this.simpleMap = simpleMap;
  }
  public java.util.Set<Long> getSimpleSet() {
    return simpleSet;
  }
  public void setSimpleSet(java.util.Set<Long> simpleSet) {
    this.simpleSet = simpleSet;
  }
  
}
   

File Name  :  
com/bethecoder/tutorials/spring3/tests/typed_collections/TypedListInjection.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.spring3.tests.typed_collections;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import com.bethecoder.tutorials.spring3.basic.ComplexTypedBean;

public class TypedListInjection {

  /**
   @param args
   */
  public static void main(String[] args) {
    XmlBeanFactory factory = new XmlBeanFactory(
                new ClassPathResource("typed_list_inj.xml"));

    ComplexTypedBean complexBean = (ComplexTypedBeanfactory.getBean("complexBean");
    System.out.println(complexBean.getSimpleList());

  }

}
   

It gives the following output,
[12.456, 45.123, 68.456]



 
  


  
bl  br