Spring本身就提供了对JAX-WS的支持,有兴趣的读者可以研究下Spring的Spring-WS项目,项目地址:

http://docs.spring.io/spring-ws/sites/1.5/downloads/releases.html

基于Spring IoC容器发布Web服务,能够大大降低WebService实现过程,也能够更好的与企业级应用进行整合,本文將和大家介绍如何基于Spring和JAX-WS发布WebService。

我们首先需要获取项目所依赖的Jar包,这个过程比较繁琐,笔者采用Maven构建项目,使用Maven进行项目管理的好处是我们只需要在pom.xml文件中配置依赖项目坐标,Maven就会自动將所需要的Jar包下载到本地仓库。

1.新建一个Maven Web项目,在pom.xml中添加如下内容:

        <dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.6</version>
</dependency>

2.新建Web服务接口和实现类,这个过程和前面两篇文中相同。

HelloWorld.java

package com.csdn.ws.recipe03;

import javax.jws.WebMethod;
import javax.jws.WebService; @WebService
public interface HelloWorld {
@WebMethod
public String sayHello(String name);
}

HelloWorldImpl.java

package com.csdn.ws.recipe03;

import javax.jws.WebService;
import org.springframework.stereotype.Component; @Component
@WebService(serviceName = "HelloWorldService", endpointInterface = "com.csdn.ws.recipe03.HelloWorld")
public class HelloWorldImpl implements HelloWorld { public String sayHello(String name) {
return "Hello," + name;
}
}

不同的是在实现类中添加了注解@Component,该注解用于Spring查找组件。

3.在web.xml文件中添加spring的监听器配置:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

4.新建一个source folder,名为config,在config下新建beans.xml,用于spring bean的配置。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.csdn.ws.recipe03"></context:component-scan>
<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://localhost:8089/services/"/>
</bean> </beans>

context:component-scan标签指定了查找组件的包名,SimpleJaxWsServiceExporter类的baseAddress属性用于指定webservice的根路径,完整的web服务地址=根路径+WebService名称。

5.完整的项目结构如下图所示:

6.通过地址http://localhost:8089/services/HelloWorldService?wsdl查看WSDL文档。



说明WebService发布成功。

7.WebService客户端调用代码请参考WebService学习之旅系列第一篇文章。

下节开始介绍开源WebService框架Apache Axis2的使用。

WebService学习之旅(三)JAX-WS与Spring整合发布WebService的更多相关文章

  1. WebService学习之旅(六)使用Apache Axis2实现WebService客户端调用

    上节介绍了如何使用Axis2 发布一个WebService,Axis2除了为我们编写WebService应用带来了便利,也同样简化的客户端调用的过程,本节在上节的基础上使用Axis2自带的工具生成客户 ...

  2. WebService学习之旅(五)基于Apache Axis2发布第一个WebService

    上篇博文介绍了如何將axis2 webservice引擎安装到Web容器中,本节开始介绍如何基于apache axis2发布第一个简单的WebService. 一.WebService服务端发布步骤 ...

  3. MyBatis学习总结(一)mybatis与spring整合

    MyBatis学习总结(一)mybatis与spring整合 一.需要的jar包 1.spring相关jar包 2.Mybatis相关的jar包 3.Spring+mybatis相关jar包 4.My ...

  4. Hadoop学习之旅三:MapReduce

    MapReduce编程模型 在Google的一篇重要的论文MapReduce: Simplified Data Processing on Large Clusters中提到,Google公司有大量的 ...

  5. 滴滴Booster移动APP质量优化框架 学习之旅 三

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 滴滴Booster移动App质量优化框架-学习之旅 二对重复资源 ...

  6. WebService学习之旅(七)Axis2发布WebService的几种方式

    前面几篇文章中简单的介绍了如何使用Axis2发布WebService及如何使用Axis2实现Web服务的客户端调用,本节將详细介绍Axis2发布WebService的几种方式. 一.使用aar包方式发 ...

  7. WebService学习之旅(四)Apache Axis2的安装

    一.Axis2简介 Axis2是目前使用较多的WebService引擎,它是Axis1.x的升级版本,不仅支持SOAP1.1和SOAP1.2,而且也提供了对REST风格WebService的支持. A ...

  8. WebService学习之旅(二)JAX-WS基于Web容器发布WebService

    在上节中我们定义Web服务接口和实现类后,调用Endpoint类的静态方法publish发布来webservice,这种方法使用起来虽然简单,但是对于一个企业级应用来说通常对外提供的服务可能不止一个, ...

  9. WebService 学习之路(一):了解并使用webService

    webService主要用于向其他系统提供接口以便调用,系统间可能开发语言等完全不同,根据约定的接口规范,调用者传递相关参数进行接口调用,服务方根据传入的条件进行业务处理并进行结果返回. webSer ...

随机推荐

  1. eclipse 查找controller

    一.打开eclipse: 二.同时按住Ctrl + Shift + R ; 弹出框如下: 在红色输入框内输入controller 名字即可. 查找控制器里面的方法:Ctrl + O

  2. Watir 简化日常工作实例

    公司的官方主页要优化搜索任务,一共有110个独立页面,开发工程师做了以下工作:1. 为所有这些页面的每个图片添加了alt:2. 为页面上的每个标题添加了面包屑:3. 为网站最重要的标题设置H1标签,而 ...

  3. bzoj4247挂饰——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4247 就是01背包: 把挂钩数限制在n以内,因为不需要更多,而这会带来一些问题,就是有很多挂 ...

  4. tyvj1940创世纪——贪心(基环树)

    题目:http://www.joyoi.cn/problem/tyvj-1940 基环树的样子,看了书上的讲解,准备写树上DP,然后挂了: #include<iostream> #incl ...

  5. spring boot 部署 发布

    Spring Boot应用的打包和部署 字数639 阅读2308 评论0 喜欢5 现在的IT开发,DevOps渐渐获得技术管理人员支持.云计算从ECS转向Docker容器技术.微服务的概念和讨论也越来 ...

  6. Nwjs简单配置

    1.创建一个工程,配置一个  package.json 文件 { "name": "application-name", "version" ...

  7. android调试之adb

    ADB 其实大部分的PC开发机与Android设备的操作都是通过adb(android debug bridge)技术完成的,这是一个C/S架构的命令行工具,主要由三个部分组成 运行在PC开发机上的命 ...

  8. Multipath TCP on iOS11 : A closer look at the TCP Options(转)

    Multipath TCP uses a variety of TCP options to use different paths simultaneously. Several Multipath ...

  9. 【Hadoop】MapReduce笔记(二):MapReduce容错,任务失败处理

    典型问题:Hadoop如何判断一个任务失败?失败了怎么做? 分析:实际情况下,用户代码存在软件错误.进程崩溃.机器故障等都会导致失败.Hadoop判断的失败有不同级别类型,针对不同级别的失败有不同的处 ...

  10. humans.txt学习理解

    可以通过以下链接访问到Google的humans.txt https://www.google.com/humans.txt 百度上有关于humans.txt的介绍 http://baike.baid ...