cxf动态调用webservice慢的解决方案

CXF初次调用webservce很慢,是因为创建的过程比较耗时

初步方案可以结合缓存(redis等)加快调用过程

//定义缓存,加快创建效率
	public static Map factoryMap=new HashMap();
	public static Map clientMap=new HashMap();
	
public  static String dynamicCallWebServiceByCXF(String wsdlUrl,String methodName,String targetNamespace,String name,List 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缓存

完整代码可以参考

cxf动态调用webservice(参数包含多个形参、List集合、JAVABean对象)

你可能感兴趣的:(技能点)