Apache Cxf WebService整合Spring(2)

六:部署项目,启动Tomcat,发布WebService,在浏览器输入http://localhost:8080/Spring-Cxf-Demo/lzw/cxf?wsdl


Apache Cxf WebService整合Spring(2)_第1张图片


七:配置apache-cxf(在环境变量Path中加入:;F:\Java\WebService\CXF\apache-cxf-2.7.6\bin)


Apache Cxf WebService整合Spring(2)_第2张图片


八:生成客户端代码

(1)在本地建立Test 工程


(2)在src目录下输入 wsdl2java http://localhost:8080/Spring-Cxf-Demo/lzw/cxf?wsdl



九:添加测试代码

Apache Cxf WebService整合Spring(2)_第3张图片

   

package com.lzw.springcxf.client;

import java.util.List;

import com.lzw.springcxf.service.ClubModel;
import com.lzw.springcxf.service.HandleService;
import com.lzw.springcxf.service.PlayerModel;
import com.lzw.springcxf.service.impl.HandleServiceTest;

public class WSClient {
    
	public static void main(String[] args) {
		
		HandleServiceTest factory = new HandleServiceTest();
		
		HandleService handleService = factory.getHandleServiceImplPort();
		
		System.out.println(handleService.sayName("内马尔"));
		
		ClubModel clubModel = new ClubModel();
		clubModel.setClubId(1111);
		clubModel.setClubName("巴塞罗那");
		clubModel.setCountry("西班牙");
		
		List<PlayerModel> players = handleService.getPlayerByClub(clubModel);
		for (PlayerModel play:players) {
			System.out.println(play.getPlayerName());
		}
	}
}

控制台输出:

本次西班牙国家德比的最佳球员是:内马尔
梅西
内马尔


你可能感兴趣的:(Apache Cxf WebService整合Spring(2))