`
isky
  • 浏览: 90812 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

在spring中集成webservice 框架 CXF

阅读更多
首先 构建环境

1.在eclipse下新建个web项目(我比较喜欢用eclipse),接着添加CXF必须依赖的jar包

commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar

2.添加spring    jar包

aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar

3.构建webservice 本例子是基于jdk1.5 或者更高的版本 通过注解来构建webservice

webservice的接口

package demo.spring;

import javax.jws.WebService;

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

webservice 的接口实现

package demo.spring;

import javax.jws.WebService;

@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    public String sayHi(String text) {
        return "Hello " + text;
    }
}

4 。 spring bean的配置文件

bean.xml

<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" />

<bean id="hello" class="demo.spring.HelloWorldImpl" />

<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />

<!-- 另一种写法 是

<jaxws:endpoint    id="helloWorld"   implementor="demo.spring.HelloWorldImpl"     address="/HelloWorld" />

在这里我建议不要用这种方法 ,如果实现类有的属性要通过spring依赖注入的话,这种方法只是简单的new个实现类,他的属性没有通过spring依赖注入给注入值

所有综合考虑   建议使用上面的写法!

-->
 
</beans>

5. web.xml加载bean.xml文件

<web-app>
<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>
<display-name>CXF Servlet</display-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>/services/*</url-pattern>
</servlet-mapping>
</web-app>

6.创建客户端配置文件

client-bean.xml

<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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

    <bean id="client" class="demo.spring.HelloWorld"
      factory-bean="clientFactory" factory-method="create"/>
   
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
   <property name="serviceClass" value="demo.spring.HelloWorld"/>
   <property name="address" value="http://localhost:8080/HelloWorld"/>
</bean>
  
</beans>

7.客户端访问

ApplicationContext context = ...; // your Spring ApplicationContext
HellWorld client = (HelloWorld) context.getBean("client");

OK 。。。其实就是这样的哦。。。。
分享到:
评论
3 楼 sunrise353 2010-01-13  
原因在于我加入了aop的拦截
<bean id="simpleAspect" class="demo.spring.SimpleAspect"/>
里面的函数返回为void,所以造成了没有返回。
2 楼 sunrise353 2010-01-13  
<!-- 另一种写法 是

<jaxws:endpoint    id="helloWorld"   implementor="demo.spring.HelloWorldImpl"     address="/HelloWorld" />

这种方式就可以正常的返回了
1 楼 sunrise353 2010-01-13  
<bean id="hello" class="demo.spring.HelloWorldImpl" />

<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />

这种方式的写法,客户端为什么调用方法后没有返回?服务端是有正常的响应的。

相关推荐

    webservice的CXF框架最新版

    最新版的cxf框架集成了spring包,下载解押后打开eclipse工程右击-&gt;build path-&gt;add librarys-&gt;user library-&gt;user librarys-&gt;new-&gt;自定义包名-&gt;选择刚才lib文件路径-&gt;ok

    用cxf开发webservice

    在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式(或binding)和网络协议(transports)包括SOAP、XML(通过HTTP或JMS)进行访问。CXF同样支持多种model 如:JAX-WS,JBI,SCA和CORBA service。CXF设计...

    ssm+cxf(基于Maven开发的ssm框架集成cxf发布web service服务)

    源码里面包含了了一个简单的插入功能,主要是为了测试mybatis是否连接上数据库的时候写的测试类,作为一个刚学java,被抓壮丁的写服务器端的妹子,我只想说,画了我3周...如题,基于maven项目的ssm框架和cxf框架的整合。

    spring与cxf集成配置小实例

    用于webservice的开发,主要用到spring+cxf的方式实现webservice的发布与简单调用测试,不懂得可以留言给我,比较显新的框架配置,希望你会喜欢!(并包含拦截器的配置!)

    WebService with Apache CXF

    Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。...Spring 进行无缝集成。 想了解新技术的就下下来看看把,应该对你有所帮助。

    cxf与spring集成

    用webservice中的xfire框架升级到cxf框架开发的实例,供大家分享~~~~

    SSM+cxf+log4j整合框架

    SSM+cxf+log4j整合框架;springmvc+spring+mybatis整合开发,内部集成webservice技术,采用cxf框架进行实现,log4j进行日志记录

    ssh服务端cxf相关jar包

    服务端ssh框架,apache CXF与Spring集成发布WebService

    CXF WEBSERVICE入门,非常详细实用

    Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-...Spring 进行无缝集成。

    Springboot整合cxf测试项目亲测可用

    Springboot整合cxf测试项目亲测可用,精简版的boot承载cxf框架的资源!

    WebSer之CXF框架例子.docx

    Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在...

    WebService 的示例程序(含说明文档)

    附件是 WebService 的示例程序(含说明文档) :考虑到 CXF 更容易和 spring 集成,所以WebService 服务端采用了 CXF 框架, 客户端分别用 axis2 和 cxf 两种方式实现 。 框架版本 : CXF:2.3.3 Spring:2.5.6 ...

    Maven+Spring+Spring MVC+MyBatis+MySQL整合SSM框架

    Maven+Spring+Spring MVC+MyBatis+MySQL整合SSM框架; 已集成activeMq;cxf webservice;邮件;

    wsdl2java源码-CXFDemo:一个关于CXF实现jax-ws规范的webservice

    是一个开源的一个webservice,可以与spring无缝集成。支持soap1.1、1.2、RESTtful或者CORBA。 ##使用CXF实现jax-ws规范的webservice 服务端: 1、创建java工程,把cxf的jar包导入工程中 2、编写SEI,在SEI上添加@...

    apache-cxf-3.1.1

    cxf是用于webservice的开发的框架,可和spring集成开发。

    WebSevice(CXF)入门案例java工程代码

    WebService入门案例,使用CXF框架,与Spring进行整合,包括客户端工程和服务端工程。

    运用SpringDM和CXF来实现WebService的动态发布

    火龙果软件工程技术中心 在JAXWS2.0发布以前,用JAVA发布一个WebService是一件相当复杂的工作,令很多开发高手都望而却步;...在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式(或binding)和网络协议(t

    Webservice接口快速开发指导

    本文总结了当前主流的webservice开发框架的使用方法及说明,以及与spring集成需要注意的事项,共享出来希望对大家有所帮助~

    Java源码 SpringMVC Mybatis Shiro Bootstrap Rest Webservice

    集成Webservice平台,包括jaxws服务、CXF框架,配置双加密的权限认证。使服务集成更加安全。 9. Bootstrap html5提供了两套前台开环境,包括CMS和电子商务网站,使您的开发更加的简洁。 技术点: 1. Springmvc ...

Global site tag (gtag.js) - Google Analytics