gudii9
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/><propert y>
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.
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/><propert
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
How it helps in future by setting to null now. please advise
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you need this when a bean initialise a property but you want it to be null
class MyBean {
private String xyz = "abc"
...