How can I access the ApplicationContext from within a JAX-WS web service? How can I access the ApplicationContext from within a JAX-WS web service? spring spring

How can I access the ApplicationContext from within a JAX-WS web service?


import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.web.context.support.SpringBeanAutowiringSupport;@WebService(     endpointInterface = "Bla",     targetNamespace = "http://bla/v001",     wsdlLocation = "WEB-INF/wsdl/bla.wsdl",        serviceName = "BlaService",    portName = "BlaPort")public class BlaWs extends SpringBeanAutowiringSupport implements BlaPort {  @Autowired  @Qualifier("dao")   private Dao dao;  ...}


I don't think that the web service should have to know about web or servlet contexts or its application context. I don't see why it should have to know any of that. Shouldn't it be far more passive? Inject what it needs and let it do its work. The service interactions with a client should be based on a contract defined up front. If it has to get unknown values from a context of some kind, how will clients know what needs to be set or how to set it?

I'd go further and say that a web service should be a wrapper for a Spring service interface. It's just one more choice among all the possible ways to expose it. Your web service should do little more than marshal and unmarshal the XML request/response objects and collaborate with Spring services.


Make your web service bean extend a spring bean.

like this