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

Properties 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 properties injection.

File Name  :  
/SpringCore001/conf/collections/properties_inj.xml 

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

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

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

public class PropertiesInjection {

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

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

  }

}
   

It gives the following output,
{in=INDIA, uk=UNITED KINGDOM, us=AMERICA}
{in=INDIA, fr=FRANCE, uk=UNITED KINGDOM, us=AMERICA, cn=CHINA}



 
  


  
bl  br