springboot整合webservice接口以及碰到的问题
简单的讲一下springboot整合webservice接口以及在整合时碰到的一些问题。
1.首先,需要导入cxf的jar,可以通过maven来管理:
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>3.1.6</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxws</artifactId><version>3.2.5</version></dependency>
加入依赖后,要看cxf的版本是否适合springboot的版本,我这的springboot版本是1.5.3.RELEASE,可以在maven仓库查看版本的对应(官网地址 https://mvnrepository.com/),找到合适的cxf版本:
2.创建接口类,主要是暴露出去的方法
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;@WebService(name = "PayService", targetNamespace = "http://service.selfServiceSystem.modules.jeesite.tyky.com")
//targetNamespace一般为包名的倒叙
public interface PayService {//exclude为true的话 就是取消暴露@WebMethod(operationName="test",exclude=false)public @WebResult String test(@WebParam(name="param") String param);
}
3.接口实现类,主要编写接口方法的业务处理
import com.tyky.jeesite.modules.selfServiceSystem.service.PayService;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;import javax.jws.WebService;@WebService(serviceName ="PayService",targetNamespace="http://service.selfServiceSystem.modules.jeesite.tyky.com",endpointInterface="com.tyky.jeesite.modules.selfServiceSystem.service.PayService")
//serviceName为接口的类名
//endpointInterface为包名
//targetNamespace为包名的倒叙
@Component
public class PayServiceImpl implements PayService{@Overridepublic String test(String param) {JSONObject json = new JSONObject();json.put("webservice",param);json.put("demo",param);json.put("get",param);json.put("param",param);//String xmlResutl = XMLUtil.JsonToXml(json);return json.toString();}
}
4.编写配置文件类:
import com.tyky.jeesite.modules.selfServiceSystem.service.PayService;
import com.tyky.jeesite.modules.selfServiceSystem.service.pay.impl.PayServiceImpl;
import com.tyky.jeesite.modules.selfServiceSystem.service.pay.util.WsInterceptor;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
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 org.apache.cxf.jaxws.EndpointImpl;
import javax.xml.ws.Endpoint;@Configuration
public class CxfConfig {@Bean(name = "cxfServlet")//名字重复报错的话 重新命名public ServletRegistrationBean cxfServlet() {ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFServlet(), "/webService/*");return servletRegistrationBean;}@Bean(name = Bus.DEFAULT_BUS_ID)public SpringBus springBus() {return new SpringBus();}@Beanpublic PayService payJsonService(){return new PayServiceImpl();}@Beanpublic Endpoint endpoint() {EndpointImpl endpoint = new EndpointImpl(springBus(), payJsonService());//要发布的服务名endpoint.publish("/payService");return endpoint;}
}
5.项目运行后,就可以在这个地址上看到发布的服务:http://127.0.0.1:8888/webService/payService?wsdl ,端口根据项目具体配置,如果在配置文件中加了服务的端口和服务名,例如我这
server.port=8888
server.context-path=/selfServiceSystem
需要把访问路径改成http://127.0.0.1:8888/selfServiceSystem/webService/payService?wsdl 即可。用浏览器访问后:
6.也可以使用SoapUI进行测试,接口返回信息是否正确:
7.这样springboot整合webservice接口就完成了,我在整合的时候只要碰到的问题如下:
(1)cxf的jar包和springboot版本不匹配,导致无法访问。
(2)webservice接口类定义时,targetNamespace配置不正确,需要包名的倒叙。
(3)服务启动时,没有注意自己项目的端口和路径名,以为只要以http://127.0.0.1:8888/webService/payService?wsdl这个地址就能访问,其实还要加上 /selfServiceSystem 的项目服务,以http://127.0.0.1:8888/selfServiceSystem/webService/payService?wsdl 这个地址访问。
springboot整合webservice接口以及碰到的问题相关推荐
- SpringBoot整合WebService(服务端+客户端)
SpringBoot整合WebService(服务端+客户端) 文章目录 SpringBoot整合WebService(服务端+客户端) 一.服务端 1.项目结构 2.创建好SpringBoot项目后 ...
- SpringBoot整合WebService
WebService是一种传统的SOA技术架构,它不依赖于任何的编程语言,也不依赖于任何的技术平台,可以直接基于HTTP协议实现网络应用间的数据交互. 面向服务架构(SOA)是一个组件模型,它将应用程 ...
- SpringBoot——实现WebService接口服务端以及客户端开发
文章目录 一.服务端代码开发 1.pom依赖 2.接口类 3.接口实现类 4.webservice配置文件 2.客户端开发 (1)pom依赖 (2)封装客户端方法clientUtil (3)调用接口类 ...
- springboot 配置webservice接口
导入依赖的jar <!-- webservice cxf --><dependency><groupId>org.apache.cxf</groupId> ...
- .net webservice studio调用方法传参_springboot整合WebService简单版
一.什么是webservice 这里给大家分享一下我们的专栏<Java 进阶集中营>,每天都会给大家分享一个最新的java技术内容,有优秀的技术讯息,也欢迎分享在我的专栏里. JAVA 进 ...
- 【七】springboot整合redis(超详细)
springboot篇章整体栏目: [一]springboot整合swagger(超详细 [二]springboot整合swagger(自定义)(超详细) [三]springboot整合token(超 ...
- IDEA中进行SpringBoot整合spring-ws开发webservice接口后期要修改xsd文件流程
场景 SpringBoot整合spring-ws开发webservice接口(全流程详细教程) 参照: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/articl ...
- 基于Springboot整合RestTemplate调用Webservice接口
1.基于Springboot整合RestTemplate调用Webservice接口,如果感觉使用webservice客户端调用服务器端不会,或者不方便 的时候,可以尝试使用RestTemplate来 ...
- rabbit和mysql事务_分布式事务原理及SpringBoot整合RabbitMQ实现可靠事件,TCC事务模型及接口幂等性...
分布式事务 我们知道在单数据库系统中,实现数据的一致性,通过数据库的事务来处理比较简单.在微服务或分布式系统中,各个独立的服务都会有自己的数据库,而不是在同一个数据库中,所以当一组事务(如商品交易中, ...
- Springboot 整合 Current-Limiting 实现接口限流
该篇文章内容: 1.实现标题中提到的接口限流 2.使用压测工具jmeter给大家展现验证效果 第一部分,代码的实现 首先是导入依赖包: <dependency><groupId> ...
最新文章
- mysql内置含糊_mysql内置函数
- hdu 2669 Romantic
- 【错误记录】Android Studio 编译报错 ( AppCompat does not support the current theme features )
- 如何模拟超过 5 万用户的并发访问?
- ASP.NET的Page.IsPostBack 属性详细说明(转)
- VTK修炼之道14:图像处理_创建
- java的概率的程序_java实现一个抽奖概率类
- 【[TJOI2014]上升子序列】
- 在线拍照功能JQuery.webCap.plugin 实现
- OAuth2授权方式
- Justinmind 如何让自己的项目可以发布到网上,实现各个端打开网页就能看
- 自然语言处理中的中英文分词工具
- 西北大学计算机转专业,2021年西北大学大一新生转专业及入学考试相关规定
- 你中了微软的圈套么?
- 【音视频】iOS AVAudioSession梳理
- html如何实现空格?
- java关键字super指什么_java 关键字super详解及用法
- 如何重新设置苹果id密码_ios游戏apple账号分享韩国苹果id密码大全
- 全麦吐司和普通吐司的区别_全麦面包和白面包的区别是什么
- java计算机毕业设计基于安卓Android/微信小程序的自来水收费系统APP