maven与spring

1.简介

在本教程中,我们将学习使用JAX-WS,Spring和Maven实施合同优先的SOAP服务应用程序。 这是使用合同优先还是代码优先方法的更多设计决定。

在开发基于SOAP的Web服务应用程序时使用应用合同优先的方法最显着的好处是,可以在对合同进行必要的更改后立即与消费者/客户共享合同,因此客户应用程序和Web服务操作实施可以由不同团队同时独立完成,从而节省了大量时间。

2.实施

上面的场景是这样的场景,客户端/消费者应用程序将通过服务端点与我们的示例基于SOAP的JAX-WS Web服务示例进行交互。

首先从实现开始,首先在Eclipse中创建一个Maven项目,并确保我们继续使用与下面所示内容相似的目录结构。

首先是查看我们的pom依赖关系,它应该类似于:

pom.xml

<dependencies><!-- 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 dependencies --><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>
</dependencies>
<build><finalName>SOAPWebServiceExample</finalName><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>jaxws-maven-plugin</artifactId><version>1.12</version><configuration><wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory><packageName>com.jcombat.ws</packageName><keep>true</keep><sourceDestDir>${basedir}/target/generated/src/main/java</sourceDestDir></configuration><executions><execution><id>wsdl_import</id><goals><goal>wsimport</goal></goals></execution></executions></plugin></plugins>
</build>

请注意我们将使用的wsimport工具,以便稍后从WSDL文件生成存根文件。

现在让我们检查一下web.xml文件。

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>

接下来,我们为我们的Web服务创建一个模式文件 。 将其命名为customerService.xsd ,这将基本上为我们将要创建的WSDL文件或Web服务合同定义构造块。

customerService.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.jcombat.com/"xmlns:tns="http://ws.jcombat.com/" elementFormDefault="qualified"><element name="CustomerServiceRequest" type="tns:CustomerServiceRequestType"></element><complexType name="CustomerServiceRequestType"><sequence><element name="customerId" type="int"></element></sequence></complexType><complexType name="CustomerServiceResponseType"><sequence><element name="customer" type="tns:Customer" maxOccurs="unbounded"minOccurs="0"></element></sequence></complexType><element name="CustomerServiceResponse" type="tns:CustomerServiceResponseType"></element><complexType name="Customer"><sequence><element name="id" type="int" maxOccurs="1" minOccurs="1"></element><element name="name" type="string" maxOccurs="1" minOccurs="1"></element></sequence></complexType>
</schema>

使用我们刚创建的XML模式创建一个有效的WSDL文件。

customerService.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitionsxmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://ws.jcombat.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.jcombat.com/"name="customerService"><wsdl:types><xsd:schema targetNamespace="http://ws.jcombat.com/"><xsd:import namespace="http://ws.jcombat.com/"schemaLocation="../schema/customerService.xsd" /></xsd:schema></wsdl:types><wsdl:message name="CustomerServiceRequest"><wsdl:part name="CustomerServiceRequest" element="tns:CustomerServiceRequest" /></wsdl:message><wsdl:message name="CustomerServiceResponse"><wsdl:part name="CustomerServiceResponse" element="tns:CustomerServiceResponse" /></wsdl:message><wsdl:portType name="CustomerServicePortType"><wsdl:operation name="getCustomer"><wsdl:input name="CustomerServiceRequest" message="tns:CustomerServiceRequest" /><wsdl:output name="CustomerServiceResponse" message="tns:CustomerServiceResponse" /></wsdl:operation></wsdl:portType><wsdl:binding name="CustomerEndpointPortBinding" type="tns:CustomerServicePortType"><soap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http" /><wsdl:operation name="getCustomer"><soap:operation style="document" soapAction="getCustomer" /><wsdl:input name="CustomerServiceRequest"><soap:body use="literal" /></wsdl:input><wsdl:output name="CustomerServiceResponse"><soap:body use="literal" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="customerService"><wsdl:port name="CustomerEndpointPort" binding="tns:CustomerEndpointPortBinding"><soap:address location="http://localhost:8080/SOAPWebServiceExample/customer" /></wsdl:port></wsdl:service>
</wsdl:definitions>

接下来是从WSDL文件生成存根文件。 为此,请在系统的命令提示符下运行以下命令。

mvn clean install

/ target目录中签出生成的存根文件。

现在,在名为CustomerServiceImpl的类中创建生成的服务接口CustomerServicePortType的实现。

CustomerServiceImpl.java

package com.jcombat.service;import javax.jws.WebService;import com.jcombat.ws.Customer;
import com.jcombat.ws.CustomerServicePortType;
import com.jcombat.ws.CustomerServiceRequestType;
import com.jcombat.ws.CustomerServiceResponseType;@WebService(endpointInterface="com.jcombat.ws.CustomerServicePortType")
public class CustomerServiceImpl implements CustomerServicePortType {public CustomerServiceResponseType getCustomer(CustomerServiceRequestType customerServiceRequest) {final CustomerServiceResponseType response = new CustomerServiceResponseType();Customer customer = new Customer();customer.setId(123);customer.setName("Ramesh");response.getCustomer().add(customer);return response;}}

必须将@WebService批注应用于端点接口实现类,才能将其标记为Web服务端点。 @WebService批注告诉服务器运行时环境将该类的所有公共方法公开为Web服务方法。

我们已经完成了该应用程序。 最终检查是,当点击以下端点URI时,是否可以看到显示的WSDL内容,我们已将其指定的位置指向WSDL文件的底部。

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

下面是我们在浏览器中看到的内容。

是的,我们成功做到了。

3.运行应用程序

使用WSDL URI(http:// localhost:8080 / SOAPWebServiceExample / customer?wsdl)在SOAP UI中设置SOAP项目。

下面是当我们在SOAP UI中实际命中服务时看到的内容。

4.下载源代码

  • 下载源代码

翻译自: https://www.javacodegeeks.com/2016/02/contract-first-soap-service-spring-maven.html

maven与spring

maven与spring_与Spring和Maven签约首个SOAP服务相关推荐

  1. Spring Boot+Maven实现车牌训练、识别系统

    目录 1.项目功能 2.项目概述 3.项目环境 之前为各位朋友分享过Python+OpenCV实现车牌检测与识别,本篇博文为各位分享Spring Boot+Maven实现车牌训练.识别系统. 1.项目 ...

  2. springmvc+spring+mybatis+maven项目集成shiro进行用户权限控制【转】

    项目结构: 1.maven项目的pom中引入shiro所需的jar包依赖关系 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  3. Spring Boot Maven插件

    Spring Boot Maven插件提供了使用Spring Boot应用程序步骤如下:   重新打包:创建一个可自动执行的jar或war文件.它可以替换常规工件,或者可以使用单独的分类器附加到构建生 ...

  4. spring 的MAVEN配置

    Maven中央存储库引用: <dependencies><dependency><groupId>org.springframework</groupId&g ...

  5. spring+springmvc+maven+mongodb

    1.前言 最近项目开发使用到了spring+springmvc+maven+mongodb,项目中的框架是用springboot进项开发的,对于我们中级开发人员来说,有利有弊,好处呢是springbo ...

  6. Spring Boot——Maven使用SystemPath引用本地jar:ClassNotFoundException

    问题描述 <dependency><groupId>com.dingtalk</groupId><artifactId>dingtalk-api-sdk ...

  7. 架构之路之spring+springmvc+maven+mongodb的搭建(转载:http://blog.csdn.net/tomcat_2014/article/details/55100130)

    1.前言 最近项目开发使用到了spring+springmvc+maven+MongoDB,项目中的框架是用springboot进项开发的,对于我们中级开发人员来说,有利有弊,好处呢是springbo ...

  8. Spring boot maven 搭建框架

    Spring Boot: 目的:这个框架帮助开发者更容易地创建基于Spring的应用程序和服务,使得pring开发者能够最快速地获得所需要的Spring功能. 优点:完全不需要XML配置,让sprin ...

  9. 与Spring和Maven签订合约优先SOAP服务

    1.简介 在本教程中,我们将学习使用JAX-WS,Spring和Maven实施合同优先的SOAP服务应用程序. 这是使用合同优先还是代码优先方法的更多设计决定. 在开发基于SOAP的Web服务应用程序 ...

最新文章

  1. Linux驱动中,probe函数何时被调用
  2. 赋值给集合_ArrayList集合源码
  3. Django后端编辑图片提取主要颜色API
  4. [logstash-input-log4j]插件使用
  5. 鲜花海报,文字与花儿碰上的时候,美妙
  6. 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件
  7. wcf服务契约代理链
  8. cms查询系统(二)json形式参数的设计与解析
  9. tomcat中 JVM 内存溢出及合理配置
  10. 整理了 40 多套 Java 完整实战项目,各个精品!
  11. python3.6 pillow,【Pillow】Python图像处理
  12. 【渝粤教育】电大中专跨境电子商务理论与实务 (17)作业 题库
  13. HTML中设置图片或者文档路径,html怎么用background相对路径设置背景图片
  14. 双(三氟甲基磺酰基)酰亚胺钠 cas91742-21-1白色-类白色晶体-粉末 分子量:303.1358892
  15. 游戏私服的配置与防御选择
  16. 如何设计一个报表引擎
  17. wget和mwget的安装
  18. TRR 立志做最简单、易上手、易扩展、易维护的TP反射注释路由架构
  19. oppo通知栏的那些事儿(如何分析系统级应用)
  20. 20世纪最好的十大算法、算法笔记(2008-11-15 22:16:57、2011-04-21 19:29:05)

热门文章

  1. 洛谷P4727:图的同构计数(Polya引理)(dfs)
  2. P3642 [APIO2016]烟火表演(左偏树、函数)
  3. CF183C:Diverse Permutation(构造)
  4. P3639-[APIO2013]道路费用【最小生成树】
  5. YbtOJ#20239-[冲刺NOIP2020模拟赛Day10]连边方案【状压dp】
  6. 学习手记(2020/8/19~2021/3/19)
  7. 【Floyed】小萨的烦恼(ssl 1624)
  8. Dubbo(一)之简介
  9. JQuery AJAX请求结果的null为key时无法进入success方法
  10. JavaFX图表(一)