如何在Spring 3 MVC整合Apache CXF开发Webservice服务

2024-06-07 07:38

本文主要是介绍如何在Spring 3 MVC整合Apache CXF开发Webservice服务,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

如何在Spring 3 MVC框架下结合CXF开发Webservice服务

 

1:在Web.xml中配置WebService URL过滤器。

 

    <servlet>           <servlet-name>CXFServlet</servlet-name>            <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>            <load-on-startup>1</load-on-startup>       </servlet>        <servlet-mapping>         <servlet-name>CXFServlet</servlet-name>         <url-pattern>/ws/*</url-pattern>      </servlet-mapping> 

2:定义WebService接口

 

import javax.jws.WebParam;
import javax.jws.WebService;@WebService(serviceName="idsWebService", targetNamespace="http://idsws.ids.founder.com/")
public interface IIDSWebService {/*** 获取科室* @return*/public WDepartmentArr getDepartments();/*** 取消预约挂号* @param patientId  IDS患者标识* @param idsRegId   IDS预约标识* @return*/public String cancelRegister(@WebParam(name = "patient_id") String patientId, @WebParam(name = "ids_reg_id") String idsRegId);/*** 创建患者* @param patient* @return IDS患者标识*/public String createPatient(WPatient patient);}

 

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;@XmlRootElement(name = "WPatient")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "WPatient", propOrder = { "patientId","name", "sex", "birthday", "certNo","certType", "homeStreet", "homeTel","cellPhone", "relationName", "relationTel","healthCardNo", "fromCommunity"})
public class WPatient {/*** 证件类型字典: 01:身份证  03:护照 99:其他证件* * 性别字典: 1:男 2女 9:未说明的性别*/@XmlElement(name = "patient_id")private String patientId; // IDS患者标识  在给西城区提供的接口中 所有的patientId在IDS中都当做patient表中的patient_id@XmlElement(required = true)private String name; // 姓名@XmlElement(required = true)private String sex;// 性别代码@XmlElement(required = true)private String birthday;@XmlElement(name = "cert_no", required = true)private String certNo; // 证件号@XmlElement(name = "cert_type", required = true)private String certType; // 证件类别@XmlElement(name = "home_street")private String homeStreet;// 患者的家庭住址(可选)@XmlElement(name = "home_tel")private String homeTel;// 患者的家庭住址(可选)@XmlElement(name = "cell_phone")private String cellPhone;// 患者手机号@XmlElement(name = "relation_name")private String relationName;// 患者的家属姓名(可选)@XmlElement(name = "relation_tel")private String relationTel;// 患者的家属电话(可选)@XmlElement(name = "health_card_no")private String healthCardNo;// 医保号(可选)@XmlElement(name = "from_community", required=true)private String fromCommunity;// 来源机构编码(IDS提供)/*@XmlElement(name = "his_id")private String hisId; // his患者标识
*/public String getName() {return name;}public void setName(String name) {this.name = name;}... ....
}

 

import java.util.List;import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "WDepartmentArr", propOrder = { "wDepartment" })
public class WDepartmentArr {@XmlElement(name = "wDepartment")private List<WDepartment> wDepartment;public List<WDepartment> getwDepartment() {if (null == wDepartment) {wDepartment = new ArrayList<WDepartment>();}return wDepartment;}public void setwDepartment(List<WDepartment> wDepartment) {this.wDepartment = wDepartment;}}

 

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;import com.founder.ids.entity.Clinic;@XmlRootElement(name="WDepartment")  
@XmlAccessorType(XmlAccessType.FIELD)  
@XmlType(propOrder={"detpSn","name","abbCode","abbName"}) 
public class WDepartment {@XmlElement(name = "detp_sn", required = true)private String detpSn;@XmlElement(required = true)private String name;@XmlElement(name = "abb_code", required = true)private String abbCode;@XmlElement(name = "abb_name", required = true)private String abbName;public WDepartment(Clinic clinic){this.detpSn = clinic.getCode();this.name = clinic.getName();this.abbCode = clinic.getAbbCode();this.abbName = clinic.getAbbName();}public WDepartment() {}public String getDetpSn() {return detpSn;}......
}
 

3. 完成接口实现

 

 @Service("idsWebServiceImpl")@WebService(targetNamespace="http://idsws.ids.founder.com/" )
public class IDSWebservice implements IIDSWebService {private static Logger logger = Logger.getLogger(IDSWebservice.class);......}

 4. 在spring配置文件applicationContext-web.xml配置发布Webservice

 

 <jaxws:endpoint id="idsWebService" implementor="#idsWebServiceImpl" address="/index" publish="true" >  </jaxws:endpoint>

 5. 在tomcat部署应用访问地址如下:

 


 

 

* 使用CXF命令将定义好的WebService接口class生成WSDL文件,具体代码如下:

 

/*** @description 使用CXF工具将Java类生成WSDL* @author zhu_qhua*/
public class Java2WSDL {private Class<?> className;public String[] args1,args2,args3;/*** 构造函数* @param args 要生成WSDL的Java类*/public Java2WSDL(Class<?> className) {this.className = className; //根据Hello.class生成Hello.wsdl,生成的wsdl文件放在resource目录下args1=new String[]{"-wsdl","-d","./resource",this.className.getName()};//根据Hello.class生成Hello.wsdl,生成的文件放在根目录下的.example下args2=new String[]{"-wsdl","-cp", "./example",this.className.getName()};// 根据Hello.class生成wsdl文件,文件命名为myHello.wsdl,放在根目录下args3=new String[]{"-o","myHello.wsdl","-wsdl",this.className.getName()};}/*** 构造函数* @param className 要生成WSDL的Java类* @param wsdlFileName 要生成WSDL的文件名称(不包含扩展名)*/public Java2WSDL(Class<?> className,String wsdlFileName) {this.className = className; //根据Hello.class生成Hello.wsdl,生成的wsdl文件放在resource目录下args1=new String[]{"-wsdl","-d","./resource",this.className.getName()};//根据Hello.class生成Hello.wsdl,生成的文件放在根目录下的.example下args2=new String[]{"-wsdl","-cp", "./example",this.className.getName()};// 根据Hello.class生成wsdl文件,文件命名为myHello.wsdl,放在根目录下args3=new String[]{"-o",wsdlFileName+".wsdl","-wsdl",this.className.getName()};}/*public void java2WSDL(String[] args){JavaToWS javaToWS = new JavaToWS(args);try {javaToWS.run();} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) {Java2WSDL java2WSDL = new Java2WSDL(IDSWebservice.class);java2WSDL.java2WSDL(java2WSDL.args1);}*/
}
 

 

 

这篇关于如何在Spring 3 MVC整合Apache CXF开发Webservice服务的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1038549

相关文章

Java中流式并行操作parallelStream的原理和使用方法

《Java中流式并行操作parallelStream的原理和使用方法》本文详细介绍了Java中的并行流(parallelStream)的原理、正确使用方法以及在实际业务中的应用案例,并指出在使用并行流... 目录Java中流式并行操作parallelStream0. 问题的产生1. 什么是parallelS

Java中Redisson 的原理深度解析

《Java中Redisson的原理深度解析》Redisson是一个高性能的Redis客户端,它通过将Redis数据结构映射为Java对象和分布式对象,实现了在Java应用中方便地使用Redis,本文... 目录前言一、核心设计理念二、核心架构与通信层1. 基于 Netty 的异步非阻塞通信2. 编解码器三、

SpringBoot基于注解实现数据库字段回填的完整方案

《SpringBoot基于注解实现数据库字段回填的完整方案》这篇文章主要为大家详细介绍了SpringBoot如何基于注解实现数据库字段回填的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以了解... 目录数据库表pom.XMLRelationFieldRelationFieldMapping基础的一些代

一篇文章彻底搞懂macOS如何决定java环境

《一篇文章彻底搞懂macOS如何决定java环境》MacOS作为一个功能强大的操作系统,为开发者提供了丰富的开发工具和框架,下面:本文主要介绍macOS如何决定java环境的相关资料,文中通过代码... 目录方法一:使用 which命令方法二:使用 Java_home工具(Apple 官方推荐)那问题来了,

Java HashMap的底层实现原理深度解析

《JavaHashMap的底层实现原理深度解析》HashMap基于数组+链表+红黑树结构,通过哈希算法和扩容机制优化性能,负载因子与树化阈值平衡效率,是Java开发必备的高效数据结构,本文给大家介绍... 目录一、概述:HashMap的宏观结构二、核心数据结构解析1. 数组(桶数组)2. 链表节点(Node

Java AOP面向切面编程的概念和实现方式

《JavaAOP面向切面编程的概念和实现方式》AOP是面向切面编程,通过动态代理将横切关注点(如日志、事务)与核心业务逻辑分离,提升代码复用性和可维护性,本文给大家介绍JavaAOP面向切面编程的概... 目录一、AOP 是什么?二、AOP 的核心概念与实现方式核心概念实现方式三、Spring AOP 的关

详解SpringBoot+Ehcache使用示例

《详解SpringBoot+Ehcache使用示例》本文介绍了SpringBoot中配置Ehcache、自定义get/set方式,并实际使用缓存的过程,文中通过示例代码介绍的非常详细,对大家的学习或者... 目录摘要概念内存与磁盘持久化存储:配置灵活性:编码示例引入依赖:配置ehcache.XML文件:配置

Java 虚拟线程的创建与使用深度解析

《Java虚拟线程的创建与使用深度解析》虚拟线程是Java19中以预览特性形式引入,Java21起正式发布的轻量级线程,本文给大家介绍Java虚拟线程的创建与使用,感兴趣的朋友一起看看吧... 目录一、虚拟线程简介1.1 什么是虚拟线程?1.2 为什么需要虚拟线程?二、虚拟线程与平台线程对比代码对比示例:三

一文详解Python如何开发游戏

《一文详解Python如何开发游戏》Python是一种非常流行的编程语言,也可以用来开发游戏模组,:本文主要介绍Python如何开发游戏的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、python简介二、Python 开发 2D 游戏的优劣势优势缺点三、Python 开发 3D

Java中的.close()举例详解

《Java中的.close()举例详解》.close()方法只适用于通过window.open()打开的弹出窗口,对于浏览器的主窗口,如果没有得到用户允许是不能关闭的,:本文主要介绍Java中的.... 目录当你遇到以下三种情况时,一定要记得使用 .close():用法作用举例如何判断代码中的 input