来一个HelloWorld,SpringBoot发布WebService可简单啦。

  • 1、搭建项目
  • 2、配置pom.xml
  • 3、建services服务包
  • 4、登陆接口类
  • 5、登陆接口实现类
  • 6、创建CXF配置类
  • 7、Parameter 0 of method errorPageCustomizer in ErrorMvcAutoConfiguration 异常解决
  • 8、访问webservice
  • 9、访问wsdl

步骤 1 搭建项目

请参照这个教程搭建一个SpringBoot项目,注意,项目名字换成webService

步骤 2 配置pom.xml

<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.1.6</version>
</dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http</artifactId><version>3.1.6</version>
</dependency>

加上这两个jar包。

步骤 3 建services服务包

步骤 4 登陆接口类

设置一个登陆接口类

package com.webservice.demo.services;
import javax.jws.WebService;
import java.util.Map;@WebService(name = "LoginService",              // 暴露服务名称targetNamespace = "http://java18.cn"    // 命名空间
)
public interface LoginService {Map<String,Object> userLogin();}

步骤 5 登陆接口实现类

package com.webservice.demo.services.impl;import com.webservice.demo.services.LoginService;import javax.jws.WebService;
import java.util.HashMap;
import java.util.Map;@WebService(serviceName = "LoginService", // 与接口中指定的name一致targetNamespace = "http://java18.cn", // 与接口中的命名空间一致endpointInterface = "com.webservice.demo.services.LoginService"// 接口地址
)
public class LoginServiceImpl implements LoginService {@Overridepublic Map<String, Object> userLogin() {Map<String, Object> resultMap = new HashMap<>();resultMap.put("errCode",00000);resultMap.put("errMsg",null);return resultMap;}
}

步骤 6 创建CXF配置类

package com.webservice.demo.config;import com.webservice.demo.services.LoginService;
import com.webservice.demo.services.impl.LoginServiceImpl;
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;@Configuration
public class CxfConfig {@Beanpublic ServletRegistrationBean dispatcherServlet() {return new ServletRegistrationBean(new CXFServlet(),"/webservice/*");}@Bean(name = Bus.DEFAULT_BUS_ID)public SpringBus springBus() {return new SpringBus();}@Beanpublic LoginService loginService() {return new LoginServiceImpl();}@Beanpublic Endpoint endpoint() {EndpointImpl endpoint = new EndpointImpl(springBus(), loginService());endpoint.publish("/api");return endpoint;}}

步骤 7 Parameter 0 of method errorPageCustomizer in ErrorMvcAutoConfiguration 异常解决

现在直接启动会报错的。

解决方法如下

这个方法名字换一下就好了。

步骤 8 访问webservice

启动项目,访问http://localhost:8080/webservice/api

步骤 9 访问wsdl

http://localhost:8080/webservice/api?wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://java18.cn" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="LoginService" targetNamespace="http://java18.cn">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://java18.cn" elementFormDefault="unqualified" targetNamespace="http://java18.cn" version="1.0">
<xs:element name="userLogin" type="tns:userLogin"/>
<xs:element name="userLoginResponse" type="tns:userLoginResponse"/>
<xs:complexType name="userLogin">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="userLoginResponse">
<xs:sequence>
<xs:element name="_return">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="key" type="xs:string"/>
<xs:element minOccurs="0" name="value" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="userLoginResponse">
<wsdl:part element="tns:userLoginResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="userLogin">
<wsdl:part element="tns:userLogin" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="LoginService">
<wsdl:operation name="userLogin">
<wsdl:input message="tns:userLogin" name="userLogin"> </wsdl:input>
<wsdl:output message="tns:userLoginResponse" name="userLoginResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="LoginServiceSoapBinding" type="tns:LoginService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="userLogin">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="userLogin">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="userLoginResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="LoginService">
<wsdl:port binding="tns:LoginServiceSoapBinding" name="LoginServiceImplPort">
<soap:address location="http://localhost:8080/webservice/api"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Java小白翻身 - webservice教程2相关推荐

  1. Java小白翻身 - webservice教程1

    WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络应用间的交互. 其实WebSer ...

  2. java xfire webservice 异步_[Java教程]Java中使用webservice,简化开发(xfire的webservice)...

    [Java教程]Java中使用webservice,简化开发(xfire的webservice) 0 2016-01-07 15:00:11 首先,使用到的jar先导入项目中, xbean-sprin ...

  3. 孔浩老师 java 微信_孔浩老师JAVA WebService教程

    课程目录:01_webservice快速实例 02_wsimport的使用 03_wsdl和soap讲解(介入了tcpmon工具) 04_SOA的分析(纯属扯淡) 05_dtd讲解 06_schema ...

  4. Java:eclipse下开发webservice教程

    1           环境准备 下载wtp-all-in-one-sdk-R-1.5.4-win32,这个是eclipse的web开发插件 下载jakarta-tomcat-5.0.30 下载axi ...

  5. Java小白常问的问题大全

    Java小白在初学Java时都会遇到各种各样的问题,小编来总结一下一些常见的问题.比如,可以用%除以一个小数吗?a+=b和a=a+b的效果有区别吗?声明一个数组为什么需要花费大量时间?为什么Java库 ...

  6. Java小白入门系列 第一篇 写在前面

    2018年8月30日  22:00:17 郑州  多云 Sue Java小白入门系列 第一篇  写在前面 写在前面: 首先声明一下,本人也是正在学Java,并不是多么专业人士,只是最近受老师的启发,所 ...

  7. 最适合Java初学者学习的Java零基础入门教程

    各种各样的编程语言不断崛起,但唯有Java是牢牢占据着老大的位置,目前几乎90%以上的大中型互联网应用系统在服务器端开发首选Java. 因此,也是吸引了不少年轻人投入到Java的学习之中. 所以,今天 ...

  8. WebService教程详解

    WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求,接下来通过本文给大家介绍WebService教程详解,对webservice教程感兴趣的 ...

  9. WebService 教程(包含项目实践)

    情景引入: 时间:早晨 8 : 00 am 小白:起床起床,,,公司又来需求了,你还在睡觉,快点起来~! 我:大惊小怪,又怎么了呢?小白,别一惊一乍的,打扰我的美梦 小白:公司给了个新需求,你还记得, ...

最新文章

  1. ioS开发之c语言基础-一维数组,字符数组
  2. 实践自定义UI—View
  3. centos6.8防火墙模块未加载
  4. 电信用户流失预测案例(3)
  5. .NET 5 开源工作流框架elsa技术研究
  6. java http 异步请求框架_GitHub - huangdali/MyHttpUtils: 一个非常好用的异步网络请求框架...
  7. python py2exe_转:py2exe 生成 python 可执行文件
  8. 学习笔记(01):Oracle数据库-Oracle安装与配置
  9. echarts地图地名显示_echarts地图 省份名称自定义位置和居中解决办法
  10. 2021年南宁二中高考成绩查询,2021年广西南宁二中高考物理冲刺试卷(一).docx...
  11. 建立 CLR Stored Procedure/Function 的小範例
  12. vb6,sql与access 获取当前日期
  13. Apache Tomcat漏洞总结
  14. win10多屏显示时分别设置壁纸
  15. 2022年计算机二级考试WPS Office高级应用与设计考前冲刺题及答案
  16. react+antd搭建后台管理系统
  17. python写的点名器(内附源码)
  18. 计算机无法装会声会影,会声会影“应用程序无法启动,因为应用程序的并行配置不正确”的解决方案-会声会影中文官网...
  19. 计算机硬盘显示恢复出厂设置,如何对磁盘进行分?
  20. 什么是编码器、解码器?(CNN\RNN....)

热门文章

  1. ASP.NET Core MVC 直接运行报错:对象不支持“addEventListener”属性或方法
  2. 日语翻译--20190617
  3. 二维非稳态导热微分方程_一种二维非稳态导热问题的数值解法.pdf
  4. 如何构造最大堆和最小堆?
  5. Mac 常用开发软件安装汇总
  6. java枚举工具类_Java 枚举
  7. SIM卡读卡器的研究与设计
  8. 晓月_【游戏参考】九阴真经
  9. WIFI-DIRECT 网卡初探
  10. 微信小程序日期计算IOS无效的问题