`

CXF 2.3 集成Spring3.0入门 HelloWorld

阅读更多


最少依赖包:


web.xml 配置

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	<display-name>cxf-ws</display-name>
	<context-param>  
		<param-name>contextConfigLocation</param-name>  
		<param-value>/WEB-INF/beans.xml</param-value>  
	</context-param>  
  
	<listener>  
		<listener-class>  
            org.springframework.web.context.ContextLoaderListener   
		</listener-class>  
	</listener>  
  
	<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>
</web-app>

 

cxf 配置  bean.xml

 

 

<?xml version="1.0" encoding="UTF-8"?>  
  
<!-- START SNIPPET: beans -->  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:jaxws="http://cxf.apache.org/jaxws"  
    xsi:schemaLocation="   
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  
  
    <import resource="classpath:META-INF/cxf/cxf.xml" />  
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
  
    <jaxws:endpoint    
      id="helloWorld"    
      implementor="com.zx.cxf.service.HelloWorldImpl"    
      address="/HelloWorld" />
         
</beans>  
<!-- END SNIPPET: beans -->  

java 程序源代码 :

 

接口HelloWorld

 

 

package com.zx.cxf.service;

import java.util.Date;
import java.util.List;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
	String sayHi(@WebParam(name = "text") String text);

	Date curDate();

	List<Long> addNumber(@WebParam(name = "addToNum") Long num);
}

web service 实现类 HelloWorldImpl

 

 

 

package com.zx.cxf.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(endpointInterface = "com.zx.cxf.service.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {
	private List<Long> localNumbers;
	
	@WebMethod(operationName="sayHello",action="hello")
	public String sayHi(@WebParam(name = "text") String text) {
		return "Hello " + text;
	}
	@WebMethod(exclude=true)
	public Date curDate() {
		return new Date();
	}

	public List<Long> addNumber(@WebParam(name = "addToNum") Long num) {
		if (localNumbers == null) {
			localNumbers = new ArrayList<Long>();
		}
		localNumbers.add(num);
		return localNumbers;
	}
}

启动,访问路径 http://localhost:8080/cxf-ws/ws/HelloWorld?wsdl 看到以下页面就表示启动成功

 

 

<wsdl:definitions name="HelloWorld" targetNamespace="http://service.cxf.zx.com/"><wsdl:types><xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://service.cxf.zx.com/"><xsd:element name="sayHi" type="tns:sayHi"/><xsd:complexType name="sayHi"><xsd:sequence><xsd:element minOccurs="0" name="text" type="xsd:string"/></xsd:sequence></xsd:complexType><xsd:element name="sayHiResponse" type="tns:sayHiResponse"/><xsd:complexType name="sayHiResponse"><xsd:sequence><xsd:element minOccurs="0" name="return" type="xsd:string"/></xsd:sequence></xsd:complexType><xsd:element name="addNumber" type="tns:addNumber"/><xsd:complexType name="addNumber"><xsd:sequence><xsd:element minOccurs="0" name="addToNum" type="xsd:long"/></xsd:sequence></xsd:complexType><xsd:element name="addNumberResponse" type="tns:addNumberResponse"/><xsd:complexType name="addNumberResponse"><xsd:sequence><xsd:element maxOccurs="unbounded" minOccurs="0" name="return" type="xsd:long"/></xsd:sequence></xsd:complexType></xsd:schema></wsdl:types><wsdl:message name="addNumber"><wsdl:part element="tns:addNumber" name="parameters">
    </wsdl:part></wsdl:message><wsdl:message name="addNumberResponse"><wsdl:part element="tns:addNumberResponse" name="parameters">
    </wsdl:part></wsdl:message><wsdl:message name="sayHiResponse"><wsdl:part element="tns:sayHiResponse" name="parameters">
    </wsdl:part></wsdl:message><wsdl:message name="sayHi"><wsdl:part element="tns:sayHi" name="parameters">
    </wsdl:part></wsdl:message><wsdl:portType name="HelloWorld"><wsdl:operation name="sayHi"><wsdl:input message="tns:sayHi" name="sayHi">
    </wsdl:input><wsdl:output message="tns:sayHiResponse" name="sayHiResponse">
    </wsdl:output></wsdl:operation><wsdl:operation name="addNumber"><wsdl:input message="tns:addNumber" name="addNumber">
    </wsdl:input><wsdl:output message="tns:addNumberResponse" name="addNumberResponse">
    </wsdl:output></wsdl:operation></wsdl:portType><wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="sayHi"><soap:operation soapAction="" style="document"/><wsdl:input name="sayHi"><soap:body use="literal"/></wsdl:input><wsdl:output name="sayHiResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="addNumber"><soap:operation soapAction="" style="document"/><wsdl:input name="addNumber"><soap:body use="literal"/></wsdl:input><wsdl:output name="addNumberResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="HelloWorld"><wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldImplPort"><soap:address location="http://localhost:8080/CXF-WS-1/ws/HelloWorld"/></wsdl:port></wsdl:service></wsdl:definitions>

  set CXF_HOME=D:\apache-cxf-2.3.5

     set JAVA_HOME=D:\Java\jdk1.6.0

     然后命令生成 :wsdl2java -p 包名 -d 生成文件存放的目录(必须存在) -client  http://IP:端口/XX/XXService?wsdl

     cxf会自动生成clent示例代码

 

 

 

axis :将链接保存至 .wsdl 文件,然后通过eclipse右键直接生成,也可通过新建一个工程然后通过url来生成,再拷贝出去。

         实例化proxy类进行调用即可。

 

分享到:
评论

相关推荐

    CXF2.1.3+spring3.0+struts2.3.4

    【标题】"CXF2.1.3+spring3.0+struts2.3.4" 描述了集成这三大框架实现Web服务的场景。CXF是一个开源的服务框架,它允许开发人员创建和消费各种Web服务。Spring是Java企业级应用的核心框架,提供了依赖注入和面向切面...

    web service cxf 2.7.5 与spring 3.0 集成

    在本篇中,我们将深入探讨如何将Apache CXF 2.7.5版本与Spring 3.0框架集成,以便在Java应用程序中创建和消费Web服务。 **一、CXF简介** Apache CXF是一个全面的Web服务框架,它支持多种协议,如SOAP、RESTful HTTP...

    CXF2.6+SPRING3.0+STRUTS2.3例子含Jar包

    总之,CXF2.6+Spring3.0+Struts2.3的整合提供了构建复杂Web应用程序的能力,通过它们的协作,开发者可以轻松地创建和管理Web服务、实现松散耦合的业务逻辑以及构建用户友好的交互界面。通过这个示例,学习者可以深入...

    CXF3.0+Spring3.2 HelloWorld实例

    在本教程中,我们将深入探讨如何使用Apache CXF 3.0与Spring 3.2框架构建一个简单的"Hello World" Web服务实例。这个过程涵盖了关键的技术组件、配置步骤以及可能遇到的问题解决策略。 首先,Apache CXF是一个开源...

    CXF + Spring 3.0的学习例子

    本学习例子将探讨如何在Spring 3.0环境中集成和使用CXF来创建和消费Web服务。 【描述】: 虽然描述为空,但我们可以推测这是一个关于如何在实际项目中应用CXF和Spring 3.0的教程或示例。通常,这样的例子会包括...

    CXF 2.3 API DOC

    CXF 2.3 API DOC CHM是开发的必备工具之一

    cxf2.4.1+spring3.0+身份验证 webservice

    忘记删除个人的资料了,现在重新传一个,供大家学习使用,互相交流,资源内容 为rar格式的 项目,cxf 为服务器端,cxfTest 为客户端,里边有很多调用方式,还有身份验证,使用时,搭配好 客户端和服务端的spring ...

    cxf+hibernate3.0+spring3.0 完整整合代码实现

    【描述】:“此项目实现了将CXF、Hibernate3.0和Spring3.0这三个开源框架集成到一起,提供了在WebLogic和Tomcat两种应用服务器上的无缝兼容。” 【知识点详解】: 1. **CXF**:CXF是一个开源服务框架,主要用于...

    spring3.0整合Xfire1.2.6 开发webservice需要的jar包

    本篇将详细讲解如何利用Spring 3.0与Xfire 1.2.6进行集成,以开发高效的Web服务。 首先,让我们了解Spring 3.0。Spring 3.0是Spring框架的一个重大更新,引入了许多新特性和改进,如支持JSR-303 Bean Validation,...

    CXF的第一个例子helloWorld

    这个"helloWorld"示例是学习CXF入门的典型教程,旨在帮助开发者理解如何通过CXF快速地搭建服务并进行交互。 【描述】虽然描述部分为空,但根据通常的教程结构,我们可以推测这个例子会涵盖以下步骤: 1. **环境...

    CXF2.3依赖包

    【CXF2.3依赖包】是一组用于构建基于Apache CXF 2.3版本的Web服务项目的必备组件。CXF是一个开源的Java框架,它允许开发者创建和部署SOAP和RESTful Web服务。这些依赖包确保了项目可以正确运行并处理与Web服务相关的...

    spring3.2.14集成cxf3.0

    spring3.2.14集成CXF3.0完整版,下载之后部署到tomcat8.0中即可运行,不需要更多配置,适合新手研究学习。

    cxf-2.7.3与spring3.0.7整合实例

    **CXF 2.7.3 与 Spring 3.0.7 整合实例** 在企业级开发中,服务接口的实现与调用是非常重要的一环,Apache CXF 和 Spring 框架的结合提供了强大的支持。Apache CXF 是一个开源的、全面的Web服务框架,它允许开发者...

    基于Apache CXF 3.0 Spring 4.0 Maven 3.0 构建简单Restful 接口

    本教程将介绍如何利用Apache CXF 3.0、Spring 4.0和Maven 3.0这三个强大的工具来创建一个简单的RESTful接口。 Apache CXF是一个开源框架,专门用于构建Web服务,包括SOAP和RESTful接口。它提供了丰富的功能,如自动...

    Apache CXF2+Spring2.5轻松实现WebService

    Apache CXF和Spring提供了丰富的扩展点,可以集成如Spring Security来控制访问权限,使用Spring AOP来处理事务,以及通过CXF的拦截器机制来实现自定义的日志、验证等功能。 总结来说,Apache CXF 2与Spring 2.5的...

    基于spring3.0的cxf发布webservice+client的

    在这个版本中,Spring与CXF的集成变得更加顺畅,为开发人员提供了创建RESTful和SOAP Web服务的强大工具。 CXF,全称为“Camel XFire”,是一个开源的SOAP和RESTful Web服务框架。它不仅支持多种协议,如HTTP、JMS和...

    spring3.0整合cxf3.1.4所需的最小jar包

    Spring 3.0是Spring框架的一个重要版本,它引入了许多增强特性和优化,而CXF 3.1.4是Apache CXF的一个稳定版本,用于提供SOAP和RESTful Web服务的支持。本文将详细探讨如何在Spring 3.0中整合CXF 3.1.4以及所需的...

    cxf_helloworld.rar_SOA CXF_SOA JAVA _cxf_cxf helloworld_hellowor

    【标题】"cxf_helloworld.rar" 是一个关于Apache CXF框架入门的示例项目,它专注于SOA(Service-Oriented Architecture,面向服务架构)的实现,特别是使用Java技术。"SOA CXF_SOA JAVA_cxf_cxf helloworld_hello...

    CXF集成Spring

    CXF集成了Spring框架,使得构建和管理Web服务变得更加简便和灵活。本篇将深入探讨CXF与Spring的集成,以及如何通过它们来发布一个WebSocket服务的代码实例。 首先,我们了解CXF的核心功能。CXF提供了SOAP和RESTful...

Global site tag (gtag.js) - Google Analytics