WebServiceContext: Is it there a way to inject it

2019-07-30 02:36发布

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条回答
该账号已被封号
2楼-- · 2019-07-30 03:00

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

}
查看更多
登录 后发表回答