CXF初次调用webservce很慢,是因为创建的过程比较耗时
初步方案可以结合缓存(redis等)加快调用过程
//定义缓存,加快创建效率
public static Map<String,Endpoint> factoryMap=new HashMap<String, Endpoint>();
public static Map<String,Client> clientMap=new HashMap<String, Client>();
public static String dynamicCallWebServiceByCXF(String wsdlUrl,String methodName,String targetNamespace,String name,List<Object> paramList)throws Exception{
//临时增加缓存,增加创建速度
if(!factoryMap.containsKey(methodName)){
// 创建动态客户端
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
// 创建客户端连接
Client client = factory.createClient(wsdlUrl);
ClientImpl clientImpl = (ClientImpl) client;
Endpoint endpoint = clientImpl.getEndpoint();
factoryMap.put(methodName,endpoint);
clientMap.put(methodName,client);
System.out.println("初始化");
}
//从缓存中换取 endpoint、client
Endpoint endpoint=factoryMap.get(methodName);
Client client=clientMap.get(methodName);
*******
}
定义 factoryMap缓存
完整代码可以参考