hudi
hudi

Reputation: 16565

How to set null to Integer in spring context

this is small part of my context:

<property name="a" value="1"/> where a is Integer. 

How I can set null to this value ?

Upvotes: 6

Views: 3605

Answers (2)

Mesop
Mesop

Reputation: 5263

You can use the element <null/> to indicate a null value:

<property name="a" value="1"/><null/></property>

Edit: There is more information in the official spring 2.5 documentation here: http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-null-element

Upvotes: 12

Paulius Matulionis
Paulius Matulionis

Reputation: 23413

There is the way to set the null value in the Spring configuration file.

Spring:

<bean class="SampleBean">
    <property name="name"><value></value></property>
</bean>

Results in the name property being set to "", equivalent to the java code: sampleBean.setName(""). The special <null> element may be used to indicate a null value, so that:

Spring:

<bean class="ExampleBean">
    <property name="email"><null/></property>
</bean>

The above configuration is equivalent to the java code:

Java:

exampleBean.setEmail(null).

See this link: http://www.java-forums.org/java-tip/3218-how-set-null-value-springs-configuration-file.html

Upvotes: 2

Related Questions