Null And Empty
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 injecting null and empty values.
package com.bethecoder.tutorials.spring3.basic;
public class SimpleBean {
private String simpleProp;
public String getSimpleProp () {
return simpleProp;
}
public void setSimpleProp ( String simpleProp ) {
this .simpleProp = simpleProp;
}
}
package com.bethecoder.tutorials.spring3.tests.gen;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import com.bethecoder.tutorials.spring3.basic.SimpleBean;
public class EmptyAndNullTests {
/**
* @param args
*/
public static void main ( String [] args ) {
XmlBeanFactory factory = new XmlBeanFactory (
new ClassPathResource ( "empty_null.xml" )) ;
SimpleBean emptyValue = ( SimpleBean ) factory.getBean ( "emptyValue" ) ;
System.out.println ( "emptyValue : " + emptyValue.getSimpleProp ()) ;
SimpleBean nullValue = ( SimpleBean ) factory.getBean ( "nullValue" ) ;
System.out.println ( "nullValue : " + nullValue.getSimpleProp ()) ;
}
}
It gives the following output,
emptyValue :
nullValue : null