`
haijun0314
  • 浏览: 8105 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

CXF spring实例

    博客分类:
  • SOA
阅读更多
CXF spring实例

1、服务器端



package cxf;
import javax.jws.WebService;

@WebService
public interface  HelloWorld {
  public String sayHello(String text) ;
}

package cxf;

import javax.jws.WebService;

@WebService  
public class HelloWorldImpl implements HelloWorld {   
  public String sayHello(String text) {   
         return "55555555555555555555555" + text ;   
}   

}

spring-cxf.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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/jaxwshttp://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" />  
  
    <bean id="hello" class="cxf.HelloWorldImpl" />  
    <jaxws:endpoint id="helloWorld" implementor="cxf.HelloWorldImpl"  
        address="/ws" />  
  </beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <context-param>  
        <param-name>contextConfigLocation</param-name>   
        <param-value>/WEB-INF/spring-cxf.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>/*</url-pattern>  
    </servlet-mapping>
      <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list> 
</web-app>
2、客户端

package cxf;
import javax.jws.WebService;

@WebService
public interface  HelloWorld {
   public String sayHello(String text);

}

package cxf;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {

/**
  * @param args
  */
public static void main(String[] args) {
  System.out.println(System.getProperty("java.endorsed.dirs"));
  ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-cxf.xml");
      
   HelloWorld client = (HelloWorld) ctx.getBean("cxfClient");   
         String result = client.sayHello("你好!");   
         System.out.println(result);   
}

}



spring-cxf.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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/jaxwshttp://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" />  
  
    <bean id="cxfClient" class="cxf.HelloWorld"
        factory-bean="clientFactory" factory-method="create" />
  
<bean id="clientFactory"   class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="cxf.HelloWorld" />
        <property name="address" value="http://localhost:8080/ws" />
    </bean>
    </beans>
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <context-param>  
        <param-name>contextConfigLocation</param-name>   
        <param-value>/WEB-INF/spring-cxf.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>/*</url-pattern>  
    </servlet-mapping>
      <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list> 
</web-app>





注意:

1、发生如下错误时候

nested exception is java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)

解决方法:

System.out.println(System.getProperty("java.endorsed.dirs"));能取得存放目录

将jaxb-api.jar包放到%{JAVA_HOME}\jre\lib\endorsed下即可,如果没有endorsed,则新建一个.这两个jar包我放提供在附件里

2、javamail异常:java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport

解决方法:

D:\Program Files\MyEclipse 6.0\myeclipse\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_6.0.1.zmyeclipse601200710\data\libraryset\EE_5
javaee.jar包中的 mail和 activation
我将着两项删除了,我使用的是javaee5

问题被解决了


分享到:
评论

相关推荐

    cxf+spring开发webservice客户端与服务端实例

    本实例将详细阐述如何利用CXF和Spring来构建Web服务的客户端和服务端。 一、CXF简介 CXF是一个开源的Java框架,专门用于构建和消费Web服务。它支持SOAP、RESTful等多种服务模型,并且可以方便地与Spring框架集成,...

    cxf spring maven 实例

    【标题】"CXF Spring Maven 实例"是一个关于如何整合并使用这些技术创建Web服务的教程。CXF是一个开源框架,主要用于构建和部署SOAP和RESTful Web服务,Spring则是一个广泛应用的Java企业级开发框架,而Maven是项目...

    CXF&spring实例

    本文将详细探讨"CXF&spring实例"中的相关知识点,包括服务端和客户端的实现,以及如何结合Spring进行配置。 首先,让我们了解一下CXF。CXF是一个开源的Java框架,主要用于构建和开发Web服务。它支持多种Web服务标准...

    Spring CXF Restful 实例

    在这个“Spring CXF Restful实例”中,我们将深入探讨如何利用Spring CXF来创建RESTful API。REST(Representational State Transfer)是一种软件架构风格,常用于构建现代Web服务,强调简洁、无状态和基于标准的...

    cxf+spring接口实例

    本教程将通过一个具体的"CXF+Spring接口实例"来探讨如何使用这两种技术实现Web服务并进行测试。 首先,让我们理解CXF的核心功能。CXF允许开发者使用Java编程语言来实现Web服务接口,这被称为Java API for RESTful ...

    webservice cxf spring整合返回list,bean,string,json,xml项目完整实例

    【标题】:在Java EE环境中,使用Apache CXF与Spring框架整合实现Web服务,返回List、Bean、String、JSON及XML的完整项目实例 【描述】:本项目旨在展示如何在Java企业级应用(Java EE)中,通过Apache CXF框架创建...

    CXF Spring Hello简单实例

    【标题】"CXF Spring Hello简单实例"是一个关于使用Apache CXF与Spring框架结合实现一个基本的RESTful服务的教程。Apache CXF是一个开源服务框架,它允许开发人员创建和消费各种Web服务,包括SOAP和RESTful风格。...

    CXF Spring Web Service 程序

    - **服务端集成**:Spring可以管理CXF的bean,例如WebService服务器实例、服务实现类等,通过Spring配置文件进行声明式配置,使得Web服务的启动和停止更加便捷。 - **客户端集成**:Spring也支持CXF的Web服务...

    cxf开发实例2

    【标题】:“CXF开发实例2” 在Java世界中,CXF是一个开源的服务框架,它允许开发者创建和消费各种Web服务。本实例将深入探讨如何使用CXF进行Web服务客户端的开发,帮助开发者理解并掌握CXF的核心概念和技术。通过...

    简单的webservice+Cxf+Spring数据对接实例以及jar.rar

    简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...

    cxf_spring 相关 jar

    1. 配置Spring:创建一个Spring配置文件,定义CXF的Bus实例,并配置服务端点。 2. 创建服务接口:定义你的Web服务接口,通常是一个Java接口。 3. 实现服务接口:创建实现该接口的Java类,这里会包含实际的业务逻辑。...

    CXF3.0+Spring3.2 HelloWorld实例

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

    CXF结合Spring项目实例

    【CXF结合Spring项目实例】是一个综合性的教程,旨在演示如何在Java开发环境中整合Apache CXF与Spring框架,实现高效、灵活的Web服务。Apache CXF是一个开源的Web服务框架,它支持SOAP、RESTful等多种服务风格,并且...

    cxf+spring的webservice实例

    本实例将详细介绍如何使用CXF和Spring结合来创建一个Web服务。 1. **CXF简介**: CXF全称为Apache CXF,是一个开源的Web服务框架,它支持SOAP、RESTful等多种通信方式,并且能够生成和消费WSDL(Web服务描述语言)...

    CXF2+Spring2.5开发WebService实例

    在本文中,我们将深入探讨如何使用Apache CXF 2与Spring 2.5框架来开发Web服务实例。Apache CXF是一个流行的开源项目,它提供了一种简单且强大的方式来实现和消费SOAP和RESTful Web服务。Spring框架则以其模块化、...

    CXF开发实例.pdf

    本文档是一份关于Apache CXF Web服务开发的实例教程,它详细描述了Web服务的创建、部署以及在早期版本CXF与Spring集成的技术细节。文档通过具体代码示例,提供了开发人员实现类似Web服务的参考。同时,涉及了Web服务...

    cxf与Spring的整合实例(适合初学者)

    **标题解析:** "cxf与Spring的整合实例(适合初学者)" 指的是一个教程或示例项目,旨在帮助初次接触CXF和Spring框架的开发者理解如何将这两个强大的开源工具集成在一起。CXF是一个流行的开源服务框架,常用于构建...

    cxf+spring整合

    - 配置Spring上下文:在Spring配置文件中声明CXF的Bus实例,以及服务接口和服务实现类。这可以通过使用`&lt;jaxws:endpoint&gt;`或`&lt;jaxrs:server&gt;`标签来完成。 ```xml ``` - 使用Spring自动装配:通过`@...

    CXF Spring 整合

    1. **配置Spring**:在Spring配置文件中,我们需要定义CXF的Bus实例,这是CXF的核心组件,负责管理服务和客户端的生命周期。例如,我们可以使用`&lt;cxf:bus&gt;`标签来创建一个默认的Bus实例。 2. **定义服务接口和服务...

    webservice使用cxf的实例

    总的来说,"webservice使用cxf的实例"这个主题涵盖了从基础理论到实际操作的各个环节,包括CXF框架的使用、Web服务的创建与部署、客户端调用、数据绑定、安全性和Spring集成等多个方面。通过学习和实践,开发者可以...

Global site tag (gtag.js) - Google Analytics