Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Setting null values in spring

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-08-13
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.
Question by:gudii9
  • 2
LVL 92

Expert Comment

ID: 35694887
<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"
LVL 40

Accepted Solution

mrjoltcola earned 1000 total points
ID: 35695056
Setting it in spring is no different than in regular code, you set it to null if you can't assume the property is null or don't know the value of  it. You may not know what the property value is.

Author Comment

ID: 35700120
>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
LVL 92

Assisted Solution

objects earned 1000 total points
ID: 35702338
you simply might want it to be null
without <null/> there would be no way to set a property to null


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
A solution for Fortify Path Manipulation.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question