• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency injection does not seem to work

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



When I access springWSEndpointService to call one of the methods, it throws Null Pointer Exception. On line 7, 2nd code snippet, throws NPE. and in debug mode I can see that springWSEndpointService is null.

"anotherService" bean is in another xml file. springWSEndpoint is a Controller class (SimpleURLHandler)

Setter methods of both class (SpringWSEndPointService and AnotherServiceImpl) is getting called. I have checked it by having logger statement. I do not need constructor for SpringWSEndPointService class still I wrote it explicitly in the class and that is also getting called during server start up.

Cross Post : http://forum.springsource.org/showthread.php?126746-Dependency-injection-does-not-seem-to-work&p=413669#post413669
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saurabh,

I hope you are not Initializing the Object using new operator, rather you are getting the object from Spring Container.

Regards,
Hemant.
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have,



And this method is getting called as mentioned earlier. SpringWSEndPoint class extends Spring's ServletEndpointSupport if this provides anymore information.
 
Manish Sridharan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saurabh,

I suspect one of your config file is getting loaded. Have you mentioned both of the config files under "contextConfigLocation" parameter in web.xml. Alternatively, you can use spring import tag in your main spring config file to include other config files. Hope this helps.

Thanks,
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have all necessary xml files under contextConfigLocation, I think this should not be an issue as I don't get bean not found exception or something when server starts.
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now this is height of surprise,


At the time of server startup it calls this setter and it prints, this.springWSEndpointService is NOT NULL.
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saurabh,

I can see the only 2 way for this to happen is

1. you are using new operator to initialize springWSEndpoint;
2. you are using Spring container to get instance of springWSEndpoint, but prior to this code snippet of yours, you are calling springWSEndpoint bean and setting springWSEndpointService to null (this happened to me once).

Can you test your application by making your springWSEndpoint bean scope as prototype and post your result.

Regards,
Hemant

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. you are using new operator to initialize springWSEndpoint;

I am not creating the object of springWSEndpoint anywhere.

2. you are using Spring container to get instance of springWSEndpoint, but prior to this code snippet of yours, you are calling springWSEndpoint bean and setting springWSEndpointService to null (this happened to me once).

Sorry I don't understand what do you mean?

Can you test your application by making your springWSEndpoint bean scope as prototype and post your result.


I did it and now the setter does not get called at server startup time. and still I get NullPointerException.
 
Muhammad Abdul Arif
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have setter method for springWSEndpointService
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic