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

Merge Set 

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 set merging. Spring allows us to merge set elements defined in parent definition with child definition.

File Name  :  
/SpringCore001/conf/merge/merge_set.xml 

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

public class ComplexBean {

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

File Name  :  
com/bethecoder/tutorials/spring3/tests/merge/MergeSet.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.spring3.tests.merge;

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

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

public class MergeSet {

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

    ComplexBean complexBean = (ComplexBeanfactory.getBean("complexBean");
    System.out.println(complexBean.getSimpleSet());

  }

}
   

It gives the following output,
[Value1, Value2, Value3, Value4, Value5, Value6]


                    Print

   



Books Recommendation

 
 
bl  br