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.
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 = ( ComplexBean ) factory.getBean ( "complexBean" ) ;
System.out.println ( complexBean.getSimpleProps ()) ;
ComplexBean complexBean2 = ( ComplexBean ) factory.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}