六:部署项目,启动Tomcat,发布WebService,在浏览器输入http://localhost:8080/Spring-Cxf-Demo/lzw/cxf?wsdl
七:配置apache-cxf(在环境变量Path中加入:;F:\Java\WebService\CXF\apache-cxf-2.7.6\bin)
八:生成客户端代码
(1)在本地建立Test 工程
(2)在src目录下输入 wsdl2java http://localhost:8080/Spring-Cxf-Demo/lzw/cxf?wsdl
九:添加测试代码
- 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整合Spring框架来部署WebService,并通过示例代码演示了客户端如何调用发布的服务,包括获取服务接口、创建请求及解析响应结果。

被折叠的 条评论
为什么被折叠?



