Search code examples
javaspringjakarta-eejax-ws

WebServiceContext: Is it there a way to inject it any where appart from my WebService?


I'm trying get the jax-ws javax.xml.ws.WebServiceContext. I'm able to do it in my Web service this way:

@WebService
public class Service extends BaseService {

    @Resource
    WebServiceContext wsContext;

    @WebMethod
    public responseExample example(....) {...}

}

I want to get this bean any where else in my code. Would it work if I use spring?


Solution

  • After a long time trying different ways, this is how I managed to do it like this:

    WebServiceContext wscontext = null;
    try {
        Context ctx = new InitialContext();
        wscontext = (WebServiceContext) ctx.lookup("java:comp/WebServiceContext");
    } catch (NamingException e) {
    
    }