Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

Setting null values in spring

I was reading folowing lines and I did not understand clearly.

Setting null values:
 what if in order to satisfy a requirement you need to explicitly set a property to null.
 This is really
just another kind of wiring, only in this case we are wiring null instead of a value
or bean.
To set a property to null, you simply use the <null/> element.
For example, to
set a foo property to null, you’d use this:
<property name="foo"><null/><property>
Why would you ever need to do this? If you do not explicitly wire a property in
Spring, you may assume that the property is left null. But that’s not always true.
For one thing, the bean itself may set the property to some default value. Or, if
you are using autowiring, the property may be implicitly wired. In either case, you
may need to use <null/> to explicitly set the property to null.

Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

<null/> allows you to explicitly set a property to null

you need this when a bean initialise a property but you want it to be null

class MyBean {
   private String xyz = "abc"
   ...
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

>ll if you can't assume the property is null or don't know the value of  it.
How it helps in future by setting to null now. please advise
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial