Spring Boot+CXF搭建WebService服务参考资料
pom.xml文件引入包:
<!--WerbService CXF依赖-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.12</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.12</version>
</dependency>
模拟代码:
package webServiceDemo; import java.io.Serializable; /**
* TODO
* 实体类
*/
public class User implements Serializable { private String name; private String age; private String xb; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getAge() {
return age;
} public void setAge(String age) {
this.age = age;
} public String getXb() {
return xb;
} public void setXb(String xb) {
this.xb = xb;
} public User() {
} public User(String name, String age, String xb) {
this.name = name;
this.age = age;
this.xb = xb;
}
}
package webServiceDemo; import javax.jws.WebMethod;
import javax.jws.WebService; /**
* TODO
* webService接口
*/
@WebService
public interface UserWebService { @WebMethod
User getUserByName(String name);
}
package webServiceDemo; import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List; /**
* TODO
* webService接口实现类
* endpointInterface为UserWebService所在项目地址(包含接口名),targetNamespace为UserWebService所在项目地址倒序(不含接口名)
*/
@WebService(targetNamespace = "http://webServiceDemo/", endpointInterface = "webServiceDemo.UserWebService")
public class UserWebServiceImpl implements UserWebService { @Override
public User getUserByName(String name) {
List<User> userList = new ArrayList<>();
User user1 = new User("张三", "21", "男");
userList.add(user1);
User user2 = new User("李四", "19", "女");
userList.add(user2);
User needUser = new User();
for (User user : userList) {
if (!user.getName().equals(name)) {
continue;
}
needUser = user;
} return needUser;
}
}
package webServiceDemo; import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.xml.ws.Endpoint; /**
* TODO
* WebService服务发布配置
*/
@Configuration
public class WebServiceConfig { @Bean
public ServletRegistrationBean disServlet(){
return new ServletRegistrationBean(new CXFServlet(), "/service/*"); //发布服务名称
} @Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus()
{
return new SpringBus();
} @Bean
public UserWebService userWebService() {
return new UserWebServiceImpl();
} /*
WebService服务发布
*/
@Bean
public Endpoint endpoint() {
//绑定要发布的服务
EndpointImpl endpoint = new EndpointImpl(springBus(), userWebService());
endpoint.publish("/userWebService"); //显示要发布的名称
return endpoint;
}
}
然后启动项目,创建的WebService服务会随着项目启动发布,启动成功后,根据发布配置浏览器访问:
http://localhost:8080/service/userWebService?wsdl
构建服务端参考资料:
https://www.cnblogs.com/xibei666/p/8970549.html;
https://blog.csdn.net/cs_hnu_scw/article/details/80181762;
https://www.imooc.com/article/25537?block_id=tuijian_wz;
遇到的问题及解决办法:
https://www.cnblogs.com/Big-Boss/p/11912679.html;
Spring Boot+CXF搭建WebService服务参考资料的更多相关文章
- Spring Boot+CXF搭建WebService(转)
概述 最近项目用到在Spring boot下搭建WebService服务,对Java语言下的WebService了解甚少,而今抽个时间查阅资料整理下Spring Boot结合CXF打架WebServi ...
- Spring Boot+CXF搭建WebService
Spring Boot WebService开发 需要依赖Maven的Pom清单 <?xml version="1.0" encoding="UTF-8" ...
- Spring boot+CXF开发WebService
最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...
- Spring boot+CXF开发WebService Demo
最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...
- Spring Boot 实现RESTful webservice服务端实例
1.Spring Boot configurations application.yml spring: profiles: active: dev mvc: favicon: enabled: fa ...
- Spring Boot 实现RESTful webservice服务端示例
1.Spring Boot configurations application.yml spring: profiles: active: dev mvc: favicon: enabled: fa ...
- Maven+Spirng+Mybatis+CXF搭建WebService服务
https://jingyan.baidu.com/article/39810a23b1de2fb637fda66c.html
- struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例
Cxf + Spring+ myeclipse+ cxf 进行 Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...
- CXF发布webService服务以及客户端调用
这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...
随机推荐
- 『HGOI 20190917』Cruise 题解 (计算几何+DP)
题目概述 在平面直角坐标系的第$1$象限和第$4$象限有$n$个点,其中第$i$个点的坐标为$(x_i,y_i)$,有一个权值$p_i$ 从原点$O(0,0)$出发,不重复的经过一些点,最终走到原点, ...
- CUDA-F-2-0-CUDA编程模型概述1
Abstract: 本文介绍CUDA编程模型的简要结构,包括写一个简单的可执行的CUDA程序,一个正确的CUDA核函数,以及相应的调整设置内存,线程来正确的运行程序. Keywords: CUDA编程 ...
- super 和 this 的区别
一 this和super关键字区别 1.子类的构造函数如果要引用super的话,必须把super放在函数的首位.2.super(参数):调用基类中的某一个构造函数(应该为构造函数中的第一条语句)3.t ...
- node链接mongoDB及封装
// 这个模块中封装所有对数据库的常用操作 const MongoClient = require('mongodb').MongoClient; const assert = require('as ...
- 记一次关于springboot的netty版本冲突问题
冲突的地放其实很多,大概都是类似,找不到哪个方法了: 类似于: Error starting ApplicationContext. To display the conditions report ...
- MySQL_8.0与5.7区别之账户与安全
一.创建用户和用户授权 MySQL5.7创建用户和用户授权命令可以同时执行 grant all privileges on *.* to 'Gary'@'%' identified by 'Gary@ ...
- Java中的基本数据类型和引用类型
一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节,取值范围-128~127,默认值0 short:短整型,在内存中占16位,即2个字节,取值范围-32768 ...
- 教材代码完成情况测试P402(ch13课上测试)
一.任务要求 0 在Ubuntu中用自己的有位学号建一个文件,教材p402代码 1 修改代码,至少增加一个问题和答案 2 随机选多个问题中的一个进行提问,服务器要正确回答问题 3 提交运行结果截图,要 ...
- Docker关键概念阐述
要了解Docker需要对其体系结构中的几个关键概念有所了解,主要包括image.container.service.swarm.stack等. 在介绍这几个概念时,会使用到一个测试环境,这个测试环境是 ...
- 编写javad代码实现使用Scanner从键盘读取一行输入,去掉其中重复字符, 打印出不同的那些字符
package com.loaderman.test; import java.util.HashSet; import java.util.Scanner; public class Test2 { ...