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

Typed Set 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 set injection.

File Name  :  
/SpringCore001/conf/typed_collections/typed_set_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/TypedSetInjection.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 TypedSetInjection {

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

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

  }

}
   

It gives the following output,
[1111111111, 2222222222, 3333333333]



 
  


  
bl  br