*
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
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: DI is not working in my example.