WebServiceContext: Is it there a way to inject it

2019-07-30 02:15发布

问题:

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?

回答1:

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) {

}