Maven搭建webService (一) 创建服务端---使用main函数发布服务
今天和大家分享下 使用maven 搭建 webService 服务端:
首先需要在你的IDE中集成Maven。集成办法此处略。。。。。。。
1.创建一个web工程。
2.在pom文件中增加以下依赖:
<!-- spring core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.5</version>
</dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<type>pom</type>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.3</version>
</dependency>
3.创建服务接口:
包路径 net.cc.helloworld
其中:
1. @webService 表示这是一个webService
2. @webParam 说明这个参数的名称
package net.cc.helloworld; import javax.jws.WebParam;
import javax.jws.WebService; /**
* @author test
* @create 2013-11-21下午09:48:01
*/
@WebService
public interface HelloWorld { String sayHello(@WebParam(name = "text") String text); }
4.创建实现接口:
包路径 net.cc.helloworld
其中:
1. @webService(serviceName = “HelloWorld”) 应予实现的接口名称保持一致
package net.cc.helloworld; import javax.jws.WebService; /**
* @author test
* @create 2013-11-21下午09:50:31
*/
@WebService(serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld { @Override
public String sayHello(String text) {
// TODO Auto-generated method stub
System.out.println(text);
return "say " + text;
} }
5. 发布 服务
可以使用以下方式发布服务:(此发布方式不是唯一的,后续章节会提供web版本发布方式)
package net.cc.server; import javax.xml.ws.Endpoint; import net.cc.helloworld.HelloWorld;
import net.cc.helloworld.HelloWorldImpl; /**
* @author test
* @create 2013-11-21下午09:55:49
*/
public class Servers { public Servers() { HelloWorld hello = new HelloWorldImpl();
String address = "http://192.168.1.107:9000/HelloWorld";
Endpoint.publish(address, hello);
} public static void main(String[] args) { new Servers();
System.out.println("server start ...");
}
}
6. 启动成功后 会在控制台看到类似的语句,表示发布成功。
log4j:WARN No appenders could be found for logger (org.apache.cxf.bus.spring.BusApplicationContext).
log4j:WARN Please initialize the log4j system properly.
十一月 21, 2013 11:07:25 下午 org.apache.cxf.bus.spring.BusApplicationContext getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
十一月 21, 2013 11:07:26 下午 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://helloworld.cc.net/}HelloWorld from class net.cc.helloworld.HelloWorld
十一月 21, 2013 11:07:26 下午 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://192.168.1.107:9000/HelloWorld
十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info
INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info
INFO: jetty-6.1.19
十一月 21, 2013 11:07:26 下午 org.mortbay.log.Slf4jLog info
INFO: Started SelectChannelConnector@0.0.0.0:9000
server start ...
此时 打开游览器 输入 http://192.168.1.107:9000/HelloWorld?wsdl 即可看到发布的webService
Maven搭建webService (一) 创建服务端---使用main函数发布服务的更多相关文章
- Maven搭建webService (二) 创建服务端---使用web方式发布服务
今天和大家分享 使用 web方式发布 webService 服务端.客户端 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <!-- spring core ...
- Maven搭建webService (三) 创建客户端---使用Apache CXF方式实现
package test; import net.cc.web.server.HelloWorld; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean ...
- maven搭建webservice apache cxf实现
用 web方式发布 webService 服务端.客户端 一.服务器端搭建 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <project xmlns=& ...
- 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传
一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...
- go语言游戏服务端开发(三)——服务机制
五邑隐侠,本名关健昌,12年游戏生涯. 本教程以Go语言为例. P2P网络为服务进程间.服务进程与客户端间通信提供了便利,在这个基础上可以搭建服务. 在服务层,通信包可以通过定义协议号来确定该包怎 ...
- 【gRPC】C++异步服务端优化版,多服务接口样例
官方的C++异步服务端API样例可读性并不好,理解起来非常的费劲,各种状态机也并不明了,整个运行过程也容易读不懂,因此此处参考网上的博客进行了重写,以求顺利读懂. C++异步服务端实例,详细注释版 g ...
- GPS服务端(上)-Socket服务端(golang)
从第一次写GPS的服务端到现在,已经过去了八年时光.一直是用.net修修改改,从自己写的socket服务,到suppersocket,都是勉强在坚持着,没有真正的稳定过. 最近一段时间,服务端又出了两 ...
- 从创建进程到进入main函数,发生了什么?
前几天,读者群里有小伙伴提问:从进程创建后,到底是怎么进入我写的main函数的? 今天这篇文章就来聊聊这个话题. 首先先划定一下这个问题的讨论范围:C/C++语言 这篇文章主要讨论的是操作系统层面上对 ...
- SpringCloud的服务注册中心(二)注册中心服务端和两个微服务应用客户端
一.构建EurekaServer工程 1.pom.xml 2.application.yml 3. EurekaServerApp.java 4.启动EurekaServer 二.构建部署 Eurek ...
随机推荐
- Objective C中nil/Nil/NULL的区别
nil:指向oc中对象的空指针 Nil:指向oc中类的空指针 NULL:指向其他类型的空指针,如一个c类型的内存指针 NSNull:在集合对象中,表示空值的对象 若obj为nil:[obj messa ...
- linux下开发板网络速度测试记录
由于做的项目对于网络和USB的读写速度有很高的要求,因此新拿回来的板子要测试网络和usb的最佳传输速度.要考虑不少因素,先把我能想到的记录下来. 测试的环境是开发板和ubuntu虚拟机 ...
- css z-index属性
原文地址:http://www.neoease.com/css-z-index-property-and-layering-tree/ CSS 中的 z-index 属性用于设置节点的堆叠顺序, 拥有 ...
- Linux 静态库和动态库 使用说明
Linux下程序运行中,有两种库,静态库和动态库. 静态库:名字一般为libxxx.a,编译时会整合到可执行程序中,优点是运行时不需要外部函数库支持,缺点是编译后程序较大,一旦静态库改 ...
- 探索VS中C++多态实现原理
引言 最近把<深度探索c++对象模型>读了几遍,收获甚大.明白了很多以前知其然却不知其所以然的姿势.比如构造函数与拷贝构造函数什么时候被编译器合成,虚函数.实例函数.类函数的区别等等.在此 ...
- WEB应用中的SESSION知多少?
作为一名WEB开发程序员,对session的理解是最基础的,但是现状是WEB程序员遍地都是,随便一划拉一大把,不过估计能把session能透彻理解的人应该不是很多,起码我之前对此是知之甚少,偶然看到的 ...
- zedboard 中SDK 修改串口设置(波特率。。。。)
其实在zedboard SDK中不用初始化串口的也就是platform()可以不写 ,初始化在EDK导入SDK中就写好了 具体看bsp文件夹下面的汇编.但是如果我们想要在SDK中改变串口设置的话 ...
- float闭合(清除浮动)和CSS HACK
一.float 闭合(清除浮动) 将以下代码加入Global CSS 中,给需要闭合的div加上 class="clearfix" 即可,屡试不爽. <style>.c ...
- linq 日常关键字使用
1.from var scoreQuery = from student in students from score in student.Scores where score > 90 se ...
- silverlight 生成二维码
MainPage.xaml <Grid x:Name="LayoutRoot" Background="White"> <Border Bor ...