如何在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

相关文章

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.

java中long的一些常见用法

《java中long的一些常见用法》在Java中,long是一种基本数据类型,用于表示长整型数值,接下来通过本文给大家介绍java中long的一些常见用法,感兴趣的朋友一起看看吧... 在Java中,long是一种基本数据类型,用于表示长整型数值。它的取值范围比int更大,从-922337203685477

java Long 与long之间的转换流程

《javaLong与long之间的转换流程》Long类提供了一些方法,用于在long和其他数据类型(如String)之间进行转换,本文将详细介绍如何在Java中实现Long和long之间的转换,感... 目录概述流程步骤1:将long转换为Long对象步骤2:将Longhttp://www.cppcns.c

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过

Springboot整合Redis主从实践

《Springboot整合Redis主从实践》:本文主要介绍Springboot整合Redis主从的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言原配置现配置测试LettuceConnectionFactory.setShareNativeConnect