1.简介

这是一个漫长的等待,但是我终于发布了一个关于使用Spring创建第一个基于SOAP的Web服务应用程序的教程。 JAX-WS (用于XML Web服务的Java API)是用于以XML格式创建Web服务的一组API,我们最常将其称为基于SOAP的Web服务 ,希望大家都知道基本的体系结构。

2.实施

首先,让我们检查一下pom文件的配置–

pom.xml

<!-- Spring dependencies -->
<dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.2.1.RELEASE</version>
</dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.2.1.RELEASE</version>
</dependency><!-- JAX-WS -->
<dependency><groupId>org.jvnet.jax-ws-commons.spring</groupId><artifactId>jaxws-spring</artifactId><version>1.9</version>
</dependency><dependency><groupId>com.sun.xml.ws</groupId><artifactId>jaxws-rt</artifactId><version>2.2.8</version>
</dependency>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>SOAPWebServiceExample</display-name><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>customer</servlet-name><servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>customer</servlet-name><url-pattern>/customer</url-pattern></servlet-mapping></web-app>

让我们为我们的应用程序创建客户实体。

客户.java

package com.jcombat.entity;public class Customer {private int id;private String name;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}

现在让我们创建服务接口及其对应的服务实现类。

CustomerService.java

package com.jcombat.services.customers;import com.jcombat.entity.Customer;public interface CustomerService {public Customer getCustomerById(String customerId);
}

CustomerServiceImpl.java

package com.jcombat.services.customers;import com.jcombat.entity.Customer;public class CustomerServiceImpl implements CustomerService {public Customer getCustomerById(String customerId) {Customer customer = new Customer();customer.setId(123);customer.setName("Abhimanyu");return customer;}
}

下面是applicationContext的外观。

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ws="http://jax-ws.dev.java.net/spring/core"xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://jax-ws.dev.java.net/spring/core http://jax-ws.java.net/spring/core.xsdhttp://jax-ws.dev.java.net/spring/servlet http://jax-ws.java.net/spring/servlet.xsd"><bean id="customerService" class="com.jcombat.services.customers.CustomerServiceImpl"></bean><bean id="customerEndpoint" class="com.jcombat.ws.CustomerEndpoint"><property name="service" ref="customerService" /></bean><wss:binding url="/customer"><wss:service><ws:service bean="#customerEndpoint" /></wss:service></wss:binding></beans>

请注意,URL模式( / customer )绑定到了Web服务端点实现类( customerEndpoint ),如上面的代码片段所示。 下面是我们的customerEndpoint bean实现类的样子。

CustomerEndpoint.java

package com.jcombat.ws;import javax.jws.WebMethod;
import javax.jws.WebService;import com.jcombat.entity.Customer;
import com.jcombat.services.customers.CustomerService;@WebService(serviceName = "customerService")
public class CustomerEndpoint {private CustomerService service;@WebMethod(exclude = true)public void setService(CustomerService service) {this.service = service;}@WebMethod(operationName = "getCustomer")public Customer getCustomerById(String customerId) {Customer customer = service.getCustomerById(customerId);return customer;}}

请注意,@ WebService批注指示服务器运行时环境将该类的所有公共方法公开为Web服务方法。 如果要防止任何方法公开为Web服务方法,则需要使用@WebMethod(exclude = true)注释该方法,如上面的代码片段所示。 同样,如果我们想将Web服务方法命名为与类中指定的实际方法名称( getCustomerById() )不同的名称,则需要在@WebMethod批注中添加operationName属性。

  • 如果在设置项目时遇到任何依赖性问题,可以参考此链接 。

3.运行应用程序

  • http:// localhost:8080 / SOAPWebServiceExample / customer?wsdl

一旦点击了上面的URL,就可以看到显示的WSDL内容,如下面的快照所示。

我们还可以使用SOAP UI测试端点。 使用与上述相同的WSDL位置创建新的SOAP项目。

4.下载源代码

  • 下载源代码

翻译自: https://www.javacodegeeks.com/2016/02/web-service-application-jax-ws-spring.html

带有JAX-WS和Spring的Web服务应用程序相关推荐

  1. jax-ws和jax-rs_带有JAX-WS和Spring的Web服务应用程序

    jax-ws和jax-rs 1.简介 这是一个漫长的等待,但是我最终要发布有关使用Spring创建第一个基于SOAP的Web服务应用程序的教程. JAX-WS (用于XML Web服务的Java AP ...

  2. Spring RESTful Web服务中的异常处理

    1.简介 我们可能已经在Spring中遇到了几种处理RESTful Web服务应用程序中异常的方法. 在本文中,我们将尝试探索可以采取的最佳方法来实现有效的异常处理. 2.问题陈述 让我们创建一个简单 ...

  3. axis2 json_带有Java和Axis2的JSON Web服务

    axis2 json 我最近遇到一位客户,要求我使用Java Web服务重建其旧产品. 他们希望它模块化并且易于使用. 我想到的第一件事是使用宁静的方法. 但是让我烦恼的是,Java宁静的方法是使用X ...

  4. 带有Java和Axis2的JSON Web服务

    我最近遇到一位客户,要求我使用Java Web服务重建其旧产品. 他们希望它模块化并且易于使用. 我想到的第一件事是使用宁静的方法. 但是让我烦恼的是,Java宁静的方法是使用XML !,我更喜欢一种 ...

  5. Spring Restful Web服务示例 - 使用JSON/Jackson和客户端程序

    Spring Restful Web服务示例 - 使用JSON/Jackson和客户端程序 Spring是最广泛使用的Java EE框架之一.我们之前已经看到了如何使用Spring MVC来创建基于J ...

  6. Spring Restful Web服务示例 - 使用JSON,Jackson和客户端程序

    Spring Restful Web服务示例 - 使用JSON,Jackson和客户端程序 Spring是最广泛使用的Java EE框架之一.我们之前已经看到了如何使用Spring MVC来创建基于J ...

  7. spring创建web项目_使用Spring WS创建合同优先的Web服务

    spring创建web项目 1引言 本文介绍了如何使用来实现和测试SOAP Web服务 Spring Web Services项目 . 本示例将JAXB2用于(取消)编组. 为了开发服务,我将使用合同 ...

  8. 使用Spring WS创建合同优先的Web服务

    1引言 本文介绍了如何使用来实现和测试SOAP Web服务 Spring Web Services项目 . 本示例使用JAXB2进行(取消)编组. 为了开发服务,我将使用合同优先的方法,该方法首先定义 ...

  9. 带有Spring和Maven教程的JAX–WS

    Spring框架通过JAX-WS提供对Web服务的远程支持,实际上,如Spring 参考文档中所述 ,有三种将Spring POJO服务公开为JAX-WS Web服务的方式: 公开基于Servlet的 ...

最新文章

  1. 男人心疼女人的十种方式
  2. 使用SAPGUI画图
  3. 数据结构--树状数组
  4. SharePoint 2013 中自定义WCF服务
  5. centos7 mysql 开机启动_mysqld service 随开机启动 (Centos6,Centos7)
  6. ubuntu中安装apache ab命令进行简单压力测试
  7. 正态分布的前世今生:正态分布的各种推导
  8. 25.go doc 与 godoc
  9. IDEA里面添加lombok插件,编写简略风格Java代码(转)
  10. 信号与线性系统管致中第六版pdf_第五讲 信号流图
  11. 父元素上是mousedown.prevent,子元素会被携带方法,还阻止不了怎么办?
  12. Java 微信图片上传素材管理
  13. Word文档如何插入表格
  14. dlna android电视,DLNA怎么用?DLNA连接智能电视和电脑的方法分享
  15. 京东VC后台自动批量上传主图 大聪明自动传主图 c# selenium网页自动化传图
  16. eclipse里把Servers视图弄出来
  17. PHP 接入 Apple 登录对 access_token/identityToken 进行 JWT 验证
  18. NLP自然语言处理学习
  19. Nginx+PHP+MySQL分离部署+社区论坛
  20. 流计算 Oceanus | Flink JVM 内存超限的分析方法总结

热门文章

  1. Java开发必须掌握的8种网站攻防技术
  2. List转数组toArray方法
  3. 使用Servlet上传多张图片——访问提示
  4. mybatis简单案例源码详细【注释全面】——前期准备
  5. Ajax基本案例详解之$.get的实现
  6. ListView条目中有CheckBox点击事件失效问题
  7. 历年安徽省二计算机考试题库,2010安徽省计算机等级考试试题 二级ACCESS最新考试试题库...
  8. aria2c rpc php,aria2c 的基本配置,附带傻瓜式源码
  9. 局域网物理机怎么访问虚拟机
  10. spark ui_Spark UI的见解