1.运行环境

开发工具:intellij idea

JDK版本:1.8

项目管理工具:Maven 4.0.0

2.Maven Plugin管理

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>spring-boot-ws</groupId>
<artifactId>spring-boot-ws</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- CXF webservice -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.1.11</version>
</dependency>
</dependencies> </project>

3.WebService方法创建

 package com.goku.demo.controller;

 import org.springframework.stereotype.Component;

 import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService; /**
* Created by nbfujx on 2017/11/27.
*/
@Component
@WebService(serviceName = "ExampleService"
,targetNamespace="http://controller.demo.goku.com/")
public class ExampleController { @WebMethod
public String echo(@WebParam(name = "para") String para) {
return "hello"+para;
}
}

4.CxfConfig配置编写

 package com.goku.demo.config;

 import com.goku.demo.controller.ExampleController;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.xml.ws.Endpoint; /**
* Created by nbfujx on 2017/11/27.
*/
@Configuration
public class CxfConfig { @Autowired
private Bus bus; @Autowired
private ExampleController examplecontroller; @Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus,examplecontroller);
endpoint.publish("/ExampleService");//接口发布在 /NetbarServices 目录下
return endpoint;
} }

5.WsApplication启动类编写

 package com.goku.demo;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan; /**
* Created by nbfujx on 2017/10/19.
*/
// Spring Boot 应用的标识
@SpringBootApplication
@ServletComponentScan
public class WsApplication { public static void main(String[] args) {
// 程序启动入口
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
SpringApplication.run(WsApplication.class,args);
}
}

6.Cxf客户端编写

 package test.com.goku.demo.client;

 import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import com.goku.demo.controller.ExampleController; /**
* Created by nbfujx on 2017/11/27.
*/
public class CxfClient { public static void main(String[] args) {
echo();
} public static void echo() {
// 创建动态客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/services/ExampleService?wsdl");
Object[] objects = new Object[0];
try {
objects = client.invoke("echo", "str");
System.out.println("echo:" + objects[0]);
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}

7.查看测试结果

先启动cxf服务端,再进行客户端调阅

8.GITHUB地址

https://github.com/nbfujx/springBoot-learn-demo/tree/master/spring-boot-ws

待续

spring-boot整合Cxf的webservice案例的更多相关文章

  1. Spring boot 整合CXF webservice 遇到的问题及解决

    将WebService的WSDL生成的代码的命令: wsimport -p com -s . com http://localhost:8080/service/user?wsdl Spring bo ...

  2. Spring Boot 整合 Thymeleaf 完整 Web 案例

    Thymeleaf 是一种模板语言.那模板语言或模板引擎是什么?常见的模板语言都包含以下几个概念:数据(Data).模板(Template).模板引擎(Template Engine)和结果文档(Re ...

  3. Spring Boot 使用 CXF 调用 WebService 服务

    上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService.另外本来想写一篇 xfire 作为 client 端来调用 webservi ...

  4. Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询

    摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境: ...

  5. Spring Boot 整合 Fisco Bcos(区块链)

    简介 FISCO BCOS是由国内企业主导研发.对外开源.安全可控的企业级金融联盟链底层平台,由金链盟开源工作组协作打造,并于2017年正式对外开源. 目前,成熟的区块链的平台不少,之所以选择FISC ...

  6. Spring Kafka和Spring Boot整合实现消息发送与消费简单案例

    本文主要分享下Spring Boot和Spring Kafka如何配置整合,实现发送和接收来自Spring Kafka的消息. 先前我已经分享了Kafka的基本介绍与集群环境搭建方法.关于Kafka的 ...

  7. SpringBoot2.1.6 整合CXF 实现Webservice

    SpringBoot2.1.6 整合CXF 实现Webservice 前言 最近LZ产品需要对接公司内部通讯工具,采用的是Webservice接口.产品框架用的SpringBoot2.1.6,于是采用 ...

  8. Spring Boot(十四):spring boot整合shiro-登录认证和权限管理

    Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...

  9. SpringMVC4整合CXF发布WebService

    SpringMVC4整合CXF发布WebService版本:SpringMVC 4.1.6,CXF 3.1.0项目管理:apache-maven-3.3.3 pom.xml <project x ...

随机推荐

  1. brdd 惰性执行 mapreduce 提取指定类型值 WebUi 作业信息 全局临时视图 pyspark scala spark 安装

    [rdd 惰性执行] 为了提高计算效率 spark 采用了哪些机制 1-rdd 基于分布式内存数据集进行运算 2-lazy evaluation  :惰性执行,即rdd的变换操作并不是在运行该代码时立 ...

  2. LookupError: "gw_lt" is not among the defined enum values

    LookupError: "XXX" is not among the defined enum value 查找错误:“xxx”不在定义的枚举值中 model.py中没有增加对应 ...

  3. ngrinder压力测试

    文章目录 另一篇 部署demo 写脚本 压力测试 目标主机监控 可能报错 总结: 另一篇 https://blog.csdn.net/dataiyangu/article/details/888518 ...

  4. HBase备份还原OpenTSDB数据之Snapshot

    前言 本文基于伪分布式搭建 hadoop+zookeeper+hbase+opentsdb之后,想了解前因后果的可以看上一篇和上上篇. opentsdb在hbase中生成4个表(tsdb, tsdb- ...

  5. ab工具进行压力测试

    简介与安装 ab:Apache Benchmark,只要我们安装了Apache,就能够在Apache的安装目录中找到它. yum | apt 安装的Apache  ab的目录一般为/usr/bin 也 ...

  6. 软件体系结构-分层、代理、MVC、管道与过滤器

    什么是软件架构? 程序或计算系统的软件体系结构是系统的一个或多个结构,包括软件元素.这些元素的外部可见属性以及它们之间的关系. ——Software Engineering Institute(SEI ...

  7. [LeetCode] 421. Maximum XOR of Two Numbers in an Array(位操作)

    传送门 Description Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Fin ...

  8. 获取EasyUI日期输入框的值

    var date = $('#PurDate').datebox('getValue');

  9. nodejs基础-nvm和npm

    nvm npm 更新 npm install npm@latest -g 本地安装 npm install 包名称 require(”包名“) 全局安装 npm install 包名 -g 可以直接作 ...

  10. 转义BABEL的POLYFILL和RUNTIME的区别

    babel-polyfill 使用场景 Babel 默认只转换新的 JavaScript 语法,而不转换新的 API.例如,Iterator.Generator.Set.Maps.Proxy.Refl ...