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

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.

File Name  :  
/SpringCore001/conf/gen/empty_null.xml 

File Name  :  
com/bethecoder/tutorials/spring3/basic/SimpleBean.java 
   
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;
  }
  
}
   

File Name  :  
com/bethecoder/tutorials/spring3/tests/gen/EmptyAndNullTests.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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 = (SimpleBeanfactory.getBean("emptyValue");
    System.out.println("emptyValue : " + emptyValue.getSimpleProp());
    
    SimpleBean nullValue = (SimpleBeanfactory.getBean("nullValue");
    System.out.println("nullValue : " + nullValue.getSimpleProp());
  }

}
   

It gives the following output,
emptyValue : 
nullValue : null



 
  


  
bl  br