Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set null to Integer in spring context

Tags:

java

spring

this is small part of my context:

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

How I can set null to this value ?

like image 665
hudi Avatar asked May 29 '12 14:05

hudi


2 Answers

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

like image 166
Mesop Avatar answered Nov 09 '22 01:11

Mesop


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

like image 27
Paulius Matulionis Avatar answered Nov 09 '22 01:11

Paulius Matulionis