This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Spring and the fly likes DI is not working in my example. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "DI is not working in my example." Watch "DI is not working in my example." New topic
Author

DI is not working in my example.

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

Hi, I am working with SPringMVC. I am trying to use DI functionality provided by Spring, but somehow object is getting NULL value. Hence throwing NullPointerException.
My code is as follows:


Controller is as follows:




I am getting null pointer exception because:


Is LoginService Null3:NULL;















PLease tell me where I am wrong and why I am getting null.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You need to set your property "loginService" on your bean "/login.html"
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
Hi Tom, Thanks for looking into this. but I do not get where to set the loginService bean.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Add <property name="loginService" ref="loginService" /> to your /login.html bean. Follow the pattern of your viewResolver bean to add the property.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DI is not working in my example.