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 ...
随机推荐
- PHP-过滤器-连接数据库-解析XML
PHP 过滤器 what? PHP 过滤器用于验证和过滤来自非安全来源的数据,比如用户的输入. 验证和过滤用户输入或自定义数据是任何 Web 应用程序的重要组成部分. 设计 PHP 的过滤器扩展的目的 ...
- 突破大文件上传 和内网ip的端口转发
php上传大于2M文件的解决方法 2016年12月11日 :: katelyn9 阅读数 php上传大于2M文件的解决方法 如上传一个文件大于2m往往是上传不成功的解决方法: php.ini里查找 查 ...
- MySQL:如何选取Table中的50到100行
MySQL:如何选取Table中的50到100行 使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?不用担心,MySql已 经为我们提供了这样一个功能. ? 1 2 [sql] ...
- 20191114-3 Beta阶段贡献分配
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/10006 要求1 每位组员的贡献分值 贺敬文:10 王志文:9 彭思雨:8 ...
- python:科学计数法转化为浮点型数据
def as_num(x): y='{:.5f}'.format(x) # 5f表示保留5位小数点的float型 return(y) 实验一下 as_num(1.2e-4) In [3]:as_num ...
- What happens in an async method
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/task-asynchronous-pr ...
- react 的定义组件(了解)
react 中定义组件的方法 1. 定义组件 React.createClass() (被淘汰了) 定义组件中的函数 methods 的中的 this 统统指向 组件 2. 函数定义组件 定义的组件时 ...
- Memcached 在Windows和Linux的安装和使用
Memcached 把经常操作的数据导入到内存中 Memcached是一个高性能的支持分布式的内存存储系统,可以看成一个巨大的hash表.形式:key->value key(唯一键值string ...
- vue问题六:计算属性,依赖发生变化时,重新计算computed:
<el-form-item label="单价:" prop="price" > <el-input v-model="addfor ...
- IPV6基础
Pv6与IPv4的区别 Pv6报文与IPv4报文差别就两个地方: 一个是数据链路层(以太网协议)中协议类型,IPv4是0x0800,IPv6是0x86DD 另一个是IPv6 Header是40字节,I ...