Java小白翻身 - webservice教程2
来一个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相关推荐
- Java小白翻身 - webservice教程1
WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络应用间的交互. 其实WebSer ...
- java xfire webservice 异步_[Java教程]Java中使用webservice,简化开发(xfire的webservice)...
[Java教程]Java中使用webservice,简化开发(xfire的webservice) 0 2016-01-07 15:00:11 首先,使用到的jar先导入项目中, xbean-sprin ...
- 孔浩老师 java 微信_孔浩老师JAVA WebService教程
课程目录:01_webservice快速实例 02_wsimport的使用 03_wsdl和soap讲解(介入了tcpmon工具) 04_SOA的分析(纯属扯淡) 05_dtd讲解 06_schema ...
- Java:eclipse下开发webservice教程
1 环境准备 下载wtp-all-in-one-sdk-R-1.5.4-win32,这个是eclipse的web开发插件 下载jakarta-tomcat-5.0.30 下载axi ...
- Java小白常问的问题大全
Java小白在初学Java时都会遇到各种各样的问题,小编来总结一下一些常见的问题.比如,可以用%除以一个小数吗?a+=b和a=a+b的效果有区别吗?声明一个数组为什么需要花费大量时间?为什么Java库 ...
- Java小白入门系列 第一篇 写在前面
2018年8月30日 22:00:17 郑州 多云 Sue Java小白入门系列 第一篇 写在前面 写在前面: 首先声明一下,本人也是正在学Java,并不是多么专业人士,只是最近受老师的启发,所 ...
- 最适合Java初学者学习的Java零基础入门教程
各种各样的编程语言不断崛起,但唯有Java是牢牢占据着老大的位置,目前几乎90%以上的大中型互联网应用系统在服务器端开发首选Java. 因此,也是吸引了不少年轻人投入到Java的学习之中. 所以,今天 ...
- WebService教程详解
WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求,接下来通过本文给大家介绍WebService教程详解,对webservice教程感兴趣的 ...
- WebService 教程(包含项目实践)
情景引入: 时间:早晨 8 : 00 am 小白:起床起床,,,公司又来需求了,你还在睡觉,快点起来~! 我:大惊小怪,又怎么了呢?小白,别一惊一乍的,打扰我的美梦 小白:公司给了个新需求,你还记得, ...
最新文章
- ioS开发之c语言基础-一维数组,字符数组
- 实践自定义UI—View
- centos6.8防火墙模块未加载
- 电信用户流失预测案例(3)
- .NET 5 开源工作流框架elsa技术研究
- java http 异步请求框架_GitHub - huangdali/MyHttpUtils: 一个非常好用的异步网络请求框架...
- python py2exe_转:py2exe 生成 python 可执行文件
- 学习笔记(01):Oracle数据库-Oracle安装与配置
- echarts地图地名显示_echarts地图 省份名称自定义位置和居中解决办法
- 2021年南宁二中高考成绩查询,2021年广西南宁二中高考物理冲刺试卷(一).docx...
- 建立 CLR Stored Procedure/Function 的小範例
- vb6,sql与access 获取当前日期
- Apache Tomcat漏洞总结
- win10多屏显示时分别设置壁纸
- 2022年计算机二级考试WPS Office高级应用与设计考前冲刺题及答案
- react+antd搭建后台管理系统
- python写的点名器(内附源码)
- 计算机无法装会声会影,会声会影“应用程序无法启动,因为应用程序的并行配置不正确”的解决方案-会声会影中文官网...
- 计算机硬盘显示恢复出厂设置,如何对磁盘进行分?
- 什么是编码器、解码器?(CNN\RNN....)