spring-boot整合Cxf的webservice案例
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案例的更多相关文章
- Spring boot 整合CXF webservice 遇到的问题及解决
将WebService的WSDL生成的代码的命令: wsimport -p com -s . com http://localhost:8080/service/user?wsdl Spring bo ...
- Spring Boot 整合 Thymeleaf 完整 Web 案例
Thymeleaf 是一种模板语言.那模板语言或模板引擎是什么?常见的模板语言都包含以下几个概念:数据(Data).模板(Template).模板引擎(Template Engine)和结果文档(Re ...
- Spring Boot 使用 CXF 调用 WebService 服务
上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService.另外本来想写一篇 xfire 作为 client 端来调用 webservi ...
- Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询
摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境: ...
- Spring Boot 整合 Fisco Bcos(区块链)
简介 FISCO BCOS是由国内企业主导研发.对外开源.安全可控的企业级金融联盟链底层平台,由金链盟开源工作组协作打造,并于2017年正式对外开源. 目前,成熟的区块链的平台不少,之所以选择FISC ...
- Spring Kafka和Spring Boot整合实现消息发送与消费简单案例
本文主要分享下Spring Boot和Spring Kafka如何配置整合,实现发送和接收来自Spring Kafka的消息. 先前我已经分享了Kafka的基本介绍与集群环境搭建方法.关于Kafka的 ...
- SpringBoot2.1.6 整合CXF 实现Webservice
SpringBoot2.1.6 整合CXF 实现Webservice 前言 最近LZ产品需要对接公司内部通讯工具,采用的是Webservice接口.产品框架用的SpringBoot2.1.6,于是采用 ...
- Spring Boot(十四):spring boot整合shiro-登录认证和权限管理
Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...
- SpringMVC4整合CXF发布WebService
SpringMVC4整合CXF发布WebService版本:SpringMVC 4.1.6,CXF 3.1.0项目管理:apache-maven-3.3.3 pom.xml <project x ...
随机推荐
- codecs模块, decode、encode
使用codecs模块,在Python中完成字符编码 字符的编码是按照某种规则在单字节字符和多字节字符之间进行转换的某种方法.从单字节到多字节叫做decoding,从多字节到单字节叫做encodin ...
- 【SpringBoot】 Java中如何封装Http请求,以及JSON多层嵌套解析
前言 本文中的内容其实严格来说不算springboot里面的特性,属于JAVA基础,只是我在项目中遇到了,特归纳总结一下. HTTP请求封装 目前JAVA对于HTTP封装主要有三种方式: 1. JAV ...
- C-LeetCode-Shuffle an Array跑不过测试用例
使用time()作为随机数种子,一秒改变一次随机数还是不够随机,跑不过测试用例6 ,在加上个毫秒级计时精度的clock()作为随机数种子就达标了. 示例代码: typedef struct { int ...
- Gradle查看Project中的所有 Task
查看Project中所有的Task:$ gradle tasks 查看Project中所有的properties:$ gradle properties 如: 参照了: https://www.jia ...
- Kestrel web server implementation in ASP.NET Core
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore1x&view ...
- Redux生态系统
生态系统 Redux 是一个体小精悍的库,但它相关的内容和 API 都是精挑细选的,足以衍生出丰富的工具集和可扩展的生态系统. 如果需要关于 Redux 所有内容的列表,推荐移步至 Awesome R ...
- Markov Decision Process in Detail
From the last post about MDP, we know the environment consists of 5 basic elements: S:State Space of ...
- javaScript Map
} } } vertices.push(v); adjList.set ...
- JavaScript LoopQueue
function Queue() { var items = []; this.enqueue = function(element) { items.push(element) } this.deq ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...