Dependency injection does not seem to work

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.

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,

Manish S.

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 512

posted May 24, 2012 08:45:46

0

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

Joined: Sep 12, 2008
Posts: 512

posted May 24, 2012 09:25:44

0

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

Joined: Dec 23, 2008
Posts: 122

posted May 24, 2012 10:46:20

0

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

Joined: Sep 12, 2008
Posts: 512

posted May 24, 2012 11:22:33

0

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.