今天和大家分享下 使用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函数发布服务的更多相关文章

  1. Maven搭建webService (二) 创建服务端---使用web方式发布服务

    今天和大家分享 使用 web方式发布 webService 服务端.客户端 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <!-- spring core ...

  2. Maven搭建webService (三) 创建客户端---使用Apache CXF方式实现

    package test; import net.cc.web.server.HelloWorld; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean ...

  3. maven搭建webservice apache cxf实现

    用 web方式发布 webService 服务端.客户端 一.服务器端搭建 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <project xmlns=& ...

  4. 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传

    一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...

  5. go语言游戏服务端开发(三)——服务机制

    五邑隐侠,本名关健昌,12年游戏生涯. 本教程以Go语言为例.   P2P网络为服务进程间.服务进程与客户端间通信提供了便利,在这个基础上可以搭建服务. 在服务层,通信包可以通过定义协议号来确定该包怎 ...

  6. 【gRPC】C++异步服务端优化版,多服务接口样例

    官方的C++异步服务端API样例可读性并不好,理解起来非常的费劲,各种状态机也并不明了,整个运行过程也容易读不懂,因此此处参考网上的博客进行了重写,以求顺利读懂. C++异步服务端实例,详细注释版 g ...

  7. GPS服务端(上)-Socket服务端(golang)

    从第一次写GPS的服务端到现在,已经过去了八年时光.一直是用.net修修改改,从自己写的socket服务,到suppersocket,都是勉强在坚持着,没有真正的稳定过. 最近一段时间,服务端又出了两 ...

  8. 从创建进程到进入main函数,发生了什么?

    前几天,读者群里有小伙伴提问:从进程创建后,到底是怎么进入我写的main函数的? 今天这篇文章就来聊聊这个话题. 首先先划定一下这个问题的讨论范围:C/C++语言 这篇文章主要讨论的是操作系统层面上对 ...

  9. SpringCloud的服务注册中心(二)注册中心服务端和两个微服务应用客户端

    一.构建EurekaServer工程 1.pom.xml 2.application.yml 3. EurekaServerApp.java 4.启动EurekaServer 二.构建部署 Eurek ...

随机推荐

  1. Windows优化大师最新版 V7.99 Build 12.604发布

    本文由 www.169it.com 收集整理 Windows优化大师是一款功能强大的系统工具软件,它提供了全面有效且简便安全的系统检测.系统优化.系统清理.系统维护四大功能模块及数个附加的工具软件.使 ...

  2. Mvc项目右键没有控制器选项

    今天遇到了一个比较少见的问题,我用vs2010打开一个从Svn上拉下来的mvc2项目,在Controller文件夹上右键却发现没有新建控制器的选项,在View文件夹上右键也没有新建视图的选项. 我的第 ...

  3. 初识 Jenkins

    Jenkins: Jenkins 是一款获奖的跨平台持续集成和持续交付软件,可以大大提高生产力.Jenkins 用以构建和测试软件项目,帮助开发者更容易的实现项目变更的持续集成,帮助用户更容易的获取最 ...

  4. UI3_UIViewController生命周期

    // // SecondViewController.h // UI3_UIViewController生命周期 // // Created by zhangxueming on 15/7/2. // ...

  5. spring3中新增的@value注解

    在spring 3.0中,可以通过使用@value,对一些如xxx.properties文件 中的文件,进行键值对的注入,例子如下: 1 首先在applicationContext.xml中加入:   ...

  6. 【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转

    //绕着与axis平行的任意轴旋转 void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 ...

  7. Silverlight形状、画笔、变换、图像处理、几何图形

    1.形状(Ellipse.Line.Path.Polygon.Polyline 和 Rectangle) <UserControl x:Class="SharpStudy.MainPa ...

  8. Android 多国语言

    参考android 开发文档,  ISO 639-1  ISO 3166-1-alpha-2 关于中国的: 中国其他地区: https://en.wikipedia.org/wiki/ISO_3166 ...

  9. javascript 创建对象及对象原型链属性介绍

    我们知道javascript里定义一个普通对象的方法,如: let obj = {}; obj.num = 1; obj.string = 'string'; obj.func = function( ...

  10. Mysql 的MYISAM引擎拷贝出现异常——Incorrect information in file 'xxx.frm'

    MYISAM引擎有三个文件 .FRM    存储表结构 .MYD    存储数据 .MYI   存储索引 当复制表时,将这三个文件同时复制到指定目录下. 异常处理: 1. Incorrect info ...