WebServiceContext 保持为空
WebServiceContext remains null
我有两个使用 JAX-WS 实现的 Web 服务:RequestService
和 ExtendedRequestService
。
ExtendedRequestService
调用 RequestService
并将其他数据添加到响应中。
当调用 RequestService
时,WebServiceContext
被注入,但是当从 ExtendedRequestService
调用它时,它是 null 并且代码抛出 NullPointerException
.
如何正确初始化它?
这就是我从 ExtendedRequestService
调用 RequestService
的方式:
RequestServiceImpl requestService = new RequestServiceImpl();
RequestServiceResponse requestServiceResponse = requestService.performRequest(requestServiceRequest);
不确定这是否是最佳解决方案,但这似乎工作正常:
在您的服务实现中像这样声明WebServiceContext
:
private WebServiceContext wsContext;
@Resource
public void setContext(WebServiceContext context) {
this.wsContext = context;
}
然后当您需要从您的 ExtendedRequestService
调用 RequestService
时,请使用:
RequestServiceImpl requestService = new RequestServiceImpl();
requestService.setContext(wsContext); //The WebServiceContext of your ExtendedRequestService class
RequestServiceResponse requestServiceResponse = requestService.performRequest(requestServiceRequest);
我有两个使用 JAX-WS 实现的 Web 服务:RequestService
和 ExtendedRequestService
。
ExtendedRequestService
调用 RequestService
并将其他数据添加到响应中。
当调用 RequestService
时,WebServiceContext
被注入,但是当从 ExtendedRequestService
调用它时,它是 null 并且代码抛出 NullPointerException
.
如何正确初始化它?
这就是我从 ExtendedRequestService
调用 RequestService
的方式:
RequestServiceImpl requestService = new RequestServiceImpl();
RequestServiceResponse requestServiceResponse = requestService.performRequest(requestServiceRequest);
不确定这是否是最佳解决方案,但这似乎工作正常:
在您的服务实现中像这样声明WebServiceContext
:
private WebServiceContext wsContext;
@Resource
public void setContext(WebServiceContext context) {
this.wsContext = context;
}
然后当您需要从您的 ExtendedRequestService
调用 RequestService
时,请使用:
RequestServiceImpl requestService = new RequestServiceImpl();
requestService.setContext(wsContext); //The WebServiceContext of your ExtendedRequestService class
RequestServiceResponse requestServiceResponse = requestService.performRequest(requestServiceRequest);