Maven搭建webService (一) 创建服务端---使用main函数发布服务
今天和大家分享下 使用maven 搭建 webService 服务端:
首先需要在你的IDE中集成Maven。集成办法此处略。。。。。。。
1.创建一个web工程。
2.在pom文件中增加以下依赖:
1 <!-- spring core --> 2 <dependency> 3 <groupId>org.springframework</groupId> 4 <artifactId>spring-core</artifactId> 5 <version>2.5.5</version> 6 </dependency> 7 8 <!-- spring beans --> 9 <dependency> 10 <groupId>org.springframework</groupId> 11 <artifactId>spring-beans</artifactId> 12 <version>2.5.5</version> 13 </dependency> 14 15 <!-- spring context --> 16 <dependency> 17 <groupId>org.springframework</groupId> 18 <artifactId>spring-context</artifactId> 19 <version>2.5.5</version> 20 </dependency> 21 22 <!-- spring web --> 23 <dependency> 24 <groupId>org.springframework</groupId> 25 <artifactId>spring-web</artifactId> 26 <version>2.5.5</version> 27 </dependency> 28 29 <dependency> 30 <groupId>commons-logging</groupId> 31 <artifactId>commons-logging</artifactId> 32 <version>1.1</version> 33 </dependency> 34 35 <dependency> 36 <groupId>javax.xml</groupId> 37 <artifactId>jaxb-api</artifactId> 38 <version>2.1</version> 39 <type>pom</type> 40 </dependency> 41 42 <dependency> 43 <groupId>javax.xml</groupId> 44 <artifactId>jaxb-impl</artifactId> 45 <version>2.1</version> 46 </dependency> 47 48 <dependency> 49 <groupId>xfire</groupId> 50 <artifactId>saaj-api</artifactId> 51 <version>1.3</version> 52 </dependency> 53 54 <dependency> 55 <groupId>xfire</groupId> 56 <artifactId>saaj-impl</artifactId> 57 <version>1.3</version> 58 </dependency> 59 60 <dependency> 61 <groupId>wsdl4j</groupId> 62 <artifactId>wsdl4j</artifactId> 63 <version>1.6.2</version> 64 </dependency> 65 66 <dependency> 67 <groupId>org.apache.cxf</groupId> 68 <artifactId>cxf-rt-frontend-jaxws</artifactId> 69 <version>2.2.3</version> 70 </dependency> 71 <dependency> 72 <groupId>org.apache.cxf</groupId> 73 <artifactId>cxf-rt-transports-http</artifactId> 74 <version>2.2.3</version> 75 </dependency> 76 <dependency> 77 <groupId>org.apache.cxf</groupId> 78 <artifactId>cxf-rt-transports-http-jetty</artifactId> 79 <version>2.2.3</version> 80 </dependency>
3.创建服务接口:
包路径 net.cc.helloworld
其中:
1. @webService 表示这是一个webService
2. @webParam 说明这个参数的名称
1 package net.cc.helloworld; 2 3 import javax.jws.WebParam; 4 import javax.jws.WebService; 5 6 /** 7 * @author test 8 * @create 2013-11-21下午09:48:01 9 */ 10 @WebService 11 public interface HelloWorld { 12 13 String sayHello(@WebParam(name = "text") String text); 14 15 }
4.创建实现接口:
包路径 net.cc.helloworld
其中:
1. @webService(serviceName = “HelloWorld”) 应予实现的接口名称保持一致
1 package net.cc.helloworld; 2 3 import javax.jws.WebService; 4 5 /** 6 * @author test 7 * @create 2013-11-21下午09:50:31 8 */ 9 @WebService(serviceName = "HelloWorld") 10 public class HelloWorldImpl implements HelloWorld { 11 12 @Override 13 public String sayHello(String text) { 14 // TODO Auto-generated method stub 15 System.out.println(text); 16 return "say " + text; 17 } 18 19 }
5. 发布 服务
可以使用以下方式发布服务:(此发布方式不是唯一的,后续章节会提供web版本发布方式)
1 package net.cc.server; 2 3 import javax.xml.ws.Endpoint; 4 5 import net.cc.helloworld.HelloWorld; 6 import net.cc.helloworld.HelloWorldImpl; 7 8 /** 9 * @author test 10 * @create 2013-11-21下午09:55:49 11 */ 12 public class Servers { 13 14 public Servers() { 15 16 HelloWorld hello = new HelloWorldImpl(); 17 String address = "http://192.168.1.107:9000/HelloWorld"; 18 Endpoint.publish(address, hello); 19 } 20 21 public static void main(String[] args) { 22 23 new Servers(); 24 System.out.println("server start ..."); 25 } 26 }
6. 启动成功后 会在控制台看到类似的语句,表示发布成功。
1 log4j:WARN No appenders could be found for logger (org.apache.cxf.bus.spring.BusApplicationContext). 2 log4j:WARN Please initialize the log4j system properly. 3 十一月 21, 2013 11:07:25 下午 org.apache.cxf.bus.spring.BusApplicationContext getConfigResources 4 INFO: No cxf.xml configuration file detected, relying on defaults. 5 十一月 21, 2013 11:07:26 下午 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass 6 INFO: Creating Service {http://helloworld.cc.net/}HelloWorld from class net.cc.helloworld.HelloWorld 7 十一月 21, 2013 11:07:26 下午 org.apache.cxf.endpoint.ServerImpl initDestination 8 INFO: Setting the server's publish address to be http://192.168.1.107:9000/HelloWorld 9 十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info 10 INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog 11 十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info 12 INFO: jetty-6.1.19 13 十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info 14 INFO: Started SelectChannelConnector@0.0.0.0:9000 15 server start ...
此时 打开游览器 输入 http://192.168.1.107:9000/HelloWorld?wsdl 即可看到发布的webService
转载于:https://www.cnblogs.com/zhonghuazhi/p/3436600.html
Maven搭建webService (一) 创建服务端---使用main函数发布服务相关推荐
- 初解禁:SDK服务端主程序入口函数SDK服务端主程序入口函数
/******************************************************************** 函 数 名: main 功能描述: SDK服务端主程序入口函 ...
- 后端代码之服务端 - 项目工程化创建目录启动服务 -讲解篇
文章目录 前言 一. 目录创建 与 应用启动 A. 步骤如下: B. 具体cmd命令执行流,截图如下:(`部分无效,可忽略`) 二. 查看Express的欢迎页 1. 查看欢迎页的 浏览器url地址: ...
- linux main是什么进程,从创建进程到进入main函数,发生了什么?
从创建进程到进入main函数,发生了什么? 从创建进程到进入main函数,发生了什么? 前几天,读者群里有小伙伴提问:从进程创建后,到底是怎么进入我写的main函数的? 今天这篇文章就来聊聊这个话题. ...
- 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传
一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...
- java 服务端渲染_基于vue-ssr服务端渲染入门详解
第一部分 基本介绍 1.前言 服务端渲染实现原理机制:在服务端拿数据进行解析渲染,直接生成html片段返回给前端.然后前端可以通过解析后端返回的html片段到前端页面,大致有以下两种形式: 1.服务器 ...
- linux iscsi 服务端,Linux的iscsi磁盘服务
一.iSCSI简介 iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令.iSCSI限定名称用于确定发起端和目标,并采用 iq ...
- linux ssh服务端下载文件,Linux SSH服务端配置文件设置
一 SSH概述 SSH 由 IETF 的网络小组(Network Working Group)所制定:SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安 ...
- restful服务端客户端_测试RESTful服务的客户端
restful服务端客户端 开发使用RESTful Web API的应用程序可能意味着开发服务器和客户端. 为服务器端编写集成测试可以像使用Arquillian启动服务器一样容易,并且可以通过REST ...
- mPaaS 服务端核心组件:移动分析服务 MAS 架构解析
承接<开篇 | mPaaS 服务端核心组件体系概述>已经介绍移动分析服务 MAS 的主要功能和数据链路情况,包括"基础分析,自定义分析,性能分析,日志管理". 本章节, ...
- mysql5.7只安装服务端_Windows Mysql5.7.11 服务端安装详解
MySQL服务端安装过程主要是选择安装类型(自定义.典型和完整版),一般我都会选择自定义主要是为了安装到指定目录上,此过程省略,下面着重记录配置过程. 1.配置my.ini文件 在解压的目录下面复制m ...
最新文章
- 【Let‘s Encrypt】 too many failed authorizations recently: see https://letsencrypt.org/docs/rate-limit
- Linux压缩解压命令合集
- Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
- c语言标准整形,C语言整形数值范围问题
- RMAN异机恢复遭遇ORA-01547、ORA-01152、ORA-01110错误案例
- 跨域请求——jsonp与cors
- day04.2-迭代器
- 【BZOJ1061/3265】[Noi2008]志愿者招募/志愿者招募加强版 单纯形法
- 用 Python 打造属于自己的GUI图形化界面
- 【Laravel】快速查阅手册
- vue提示音_VueJS 实现管理后台新订单的语音提醒
- Locks Aren't Slow; Lock Contention Is
- 关于java开发阿里云视频直播的使用及掉坑、爬坑,欢迎入坑交流
- Unity 游戏入门 九、 精灵动画 Sprite Animation
- OBS第三方推流直播教程
- vue在微信里面的兼容问题_Vue在 iOS 微信浏览器下不能播放
- iOS摸鱼周报 第二十四期
- 无线充电技术目前发展情况如何?对单片机行业有什么启示
- 坯子库无法一键安装插件没用_坯子库插件集下载-坯子插件库下载v2020.1 官方最新版-西西软件下载...
- 如何在JavaScript中循环遍历JSON响应?