Home Tutorial Spring Spring3 Ioc Spring Null value, Set null value in Springs configuration file

 
 

Spring Null value, Set null value in Springs configuration file
Posted on: August 23, 2010 at 12:00 AM
Advertisement
In this example you will see how to set null value in the Spring configuration file

Spring Null value, Set null value in Springs configuration file

In this example you will see how to set null value in the Spring configuration file.

NullBean.java

package spring.nullvalue.example;

public class NullBean {
  private String mesg = "no value passed";

  public void setMessage(String mesg) {
    this.mesg = mesg;
  }

  public String getMessage() {
    return mesg;
  }

}

NullBeanMain.java

package spring.nullvalue.example;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class NullBeanMain {
  public static void main(String[] args) {
    BeanFactory beanfactory = new ClassPathXmlApplicationContext(
        "context.xml");
    NullBean bean = (NullBeanbeanfactory.getBean("basic");
    System.out.println(bean.getMessage());
  }
}

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
>
  <bean id="basic" class="spring.nullvalue.example.NullBean">
    <property name="message">
      <null />
    </property>
  </bean>
</beans>

When you run this application it will display output as shown below:

    null

Download this example code

Advertisement

Related Tags for Spring Null value, Set null value in Springs configuration file:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 23, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com