今天和大家分享下 使用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. Android数据库之SQLite数据库

    Android数据库之SQLite数据库 导出查看数据库文件 在android中,为某个应用程序创建的数据库,只有它可以访问,其它应用程序是不能访问的,数据库位于Android设备/data/data ...

  2. 使用script的src实现跨域和类似ajax效果

    在解决js的跨域问题的时候, 有多种方式, 其中有一种是利用script标签的src属性,因为这个属性是不受域名限制的,我们可以直接让src的这个链接指向跨域网站的一个接口, 这个接口返回的是js代码 ...

  3. 第十一篇、微信小程序-input组件

    主要属性: 效果图: ml: <!--style的优先级比class高会覆盖和class相同属性--> <!--头像--> <view style="displ ...

  4. iOS - 移动设备防丢失App

    一.原理 二.数据获取 三.报警

  5. eclipse如何创建web项目

    1.  打开eclipse,在File上New,然后选择Dynamic  Web  Project 2.  弹出的页面中如下图,在Project name中输入项目名称JavaWeb01,点击Next ...

  6. Codevs 1010 过河卒

     时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同 ...

  7. windows下 berkerly db的安装配置(修正了关键步骤)

    这个是我从别人的博客上找来的,亲测可用,确实解决了我当时遇到的一些问题. 首先,从http://www.oracle.com/technology/global/cn/software/product ...

  8. 3月7日 Maximum Subarray

    间隔2天,继续开始写LeetCodeOj. 原题: Maximum Subarray 其实这题很早就看了,也知道怎么做,在<编程珠玑>中有提到,求最大连续子序列,其实只需要O(n)的复杂度 ...

  9. 关于CORS

    前几天碰到CORS问题,只要在“Access-Control-Allow-Origin”响应头中添加对应域名即可. 今天做一个上传文件的demo,利用XMLHttpRequest向服务器发送post请 ...

  10. webBrowser执行js的方法,并返回值,c#后台取值

    private void Form1_Load(object sender, EventArgs e) { webBrowser1.Navigate(Application.StartupPath + ...