我们使用Jersy实现了Rest服务,我的问题是当从我们的其余实现中调用一些soap服务时,我们正在为下面的委托创建对象,
@POST
@Path("/forgotuserid/validate/mobilenumber")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ServiceResponse validateMobileNumber(CommunicationDTO commonDTO)
throws ApplicationException, Exception {
ChMTYWebservicesProvidersWsMTY service = new ChMTYWebservicesProvidersWsMTY();
WsMTYPortType portType = service.getChMTYWebservicesProvidersWsMTYPort();
//TODO : other stuffs go here
return response;
}
is there any way to avoid new object creation and have single here?
答案 0 :(得分:0)
如果您使用的是Spring框架,那么有一个选项Dependency Injection,您可以使用该功能。
答案 1 :(得分:0)
您可以使用以下代码编写代码:
public class SoapWSUtil{
private static WsMTYPortType type;
static {
type = (new ChMTYWebservicesProvidersWsMTY()).getChMTYWebservicesProvidersWsMTYPort();
}
public static WsMTYPortType getType(){
return type;
}
}
然后将其用作SoapWSUtil.getType()
。如果您不将状态添加到SoapWSUtil