gpt4 book ai didi

java - WebServiceContext 保持为空

转载 作者:行者123 更新时间:2023-12-02 08:29:52 29 4
gpt4 key购买 nike

我有两个使用 JAX-WS 实现的 Web 服务:RequestServiceExtendedRequestService

ExtendedRequestService 调用 RequestService 并向响应添加其他数据。调用 RequestService 时,会注入(inject) 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);

关于java - WebServiceContext 保持为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006311/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com