This is in context to a web application. My Impl class has JAX-WS
annotations and @Autowired
annotation is not working.
I get null pointer exception while retrieving the Autowired objects.
Found to solutions, both work:
- Extend
SpringBeanAutowiringSupport
and keep@Autowired
annotations intact. - Use
WebApplicationContextUtils
to get theWebapplicationContext
where beans are loaded. getBean() from this context given me the required bean.
Now, the documentation of SpringBeanAutowiringSupport
class says in NOTE
"If there is an explicit way to access the ServletContext, prefer such a way over using this class. The WebApplicationContextUtils class allows for easy access to the Spring root web application context based on the ServletContext."
What does this mean? In my web application, I am not using any servlets. My web application is also not an ONLY JAX-WS
application. It is a web application with SOAP/REST webservices
and EJBs
as well.
Which method to prefer and why? Please help.
Extending SpringBeanAutoWiringSupport is mentioned as the preffered way in the spring docs. Isn't this method also better since you wouldn't have to explicitly access the beans from the webcontext?
http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-web-services