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

Apache CXF开发WebService

阅读更多
Apache CXF是一种新型的WebService框架,使用它开发WebService将会极大的提高开发效率。CXF与Spring的集成是非常自然的,如果你不知道Spring请问Google。
CXF项目主页:http://cxf.apache.org
由于CXF集成了很多主流的工具包,所以它的体积非常大,30M+,有兴趣的研究下哪些包是非必须的,烦请告知。
费话少说,开工。
一、在Eclipse中建立一个Dynamic Web project,添加CXF/lib下所有jar到项目的lib中
二、编写Service类
2.1先建立一个接口
package com.iflysse.cxf;
import javax.jws.WebService;
@WebService
public interface IVote {
public boolean vote(String username, int point);
public int getVoteUserTotal();
public int getVotePointTotal();
}

2.2建立Service类,实现接口方法
package com.iflysse.cxf;
import javax.jws.WebService;
@WebService
public class Vote implements IVote {
private static int pointTotal;
private static int userTotal;
public int getVotePointTotal() {
return pointTotal;
}
public int getVoteUserTotal() {
return userTotal;
}
public boolean vote(String username, int point) {
userTotal++;
pointTotal+=point;
return true;
}
}

三、在Web.xml中配置CXF,使其生效
3.1在Web.xml中添加CXFServlet,为用户提供访问入口
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

3.2由于CXF与Spring是天然集成的,所以在Web.xml中添加Spring的配置
<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>

3.3在WEB-INF下建立beans.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/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="vote" implementor="com.iflysse.cxf.Vote"
address="/Vote" />
</beans>


四、运行项目,检验成果,访问http://localhost:8080/CXFDemo/services/Vote?wsdl

注:CXF与Spring集成的意义
松耦合,通过配置实现WebService的发布
可以通过Spring容器对WebService管理
分享到:
评论
1 楼 elvishehai 2009-06-30  
能不能说详细一点啊,不是要安装好多的插件吗?  如果可以发你一个你新建文档的步聚给我看一下,我十分感谢, 

相关推荐

    Apache cxf对接webservice测试环境

    1. 前端,如JAX-WS,与核心代码的彻底分离。 2. 简单易用,例如,创建客户端和端点不需标注。...在面向服务的架构(SOA)基础设施项目中,CXF通常和Apache ServiceMix,Apache Camel以及Apache ActiveMQ一起使用。

    cxf开发webservice实践

    利用Apache CXF进行WebService的开发

    用CXF开发webservice所用jar包

    最近用CXF开发webservice,发现老是报jar包的错误,但是又不能把所有从官网下载下来的都复制过来。官网下载的有好几十个呢,这是官网CXF的下载地址:http://cxf.apache.org/download.html。于是网上整理了一下,做个...

    彻底了解|利用Apache CXF框架开发WebService

    CXF就是一个WebService的框架,在生产环境中一般情况下我们都使用框架来开发,这个框架简单的说就是将WebService的开发给简化了,而且还新增了拦截器。本文将带大家利用Apache CXF快速实现一个WebService。

    使用CXF开发WebService

    这是讲解cxf的权威开发文档 文档内容:Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services

    apache-cxf_WebService

    apache-cxf_WebService

    用cxf开发webservice

    Apache CXF是一个开源的Service框架,它实现了JCP与Web Service中一些重要标准。CXF简化了构造,集成,面向服务架构(SOA)业务组件与技术的灵活复用。在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式...

    WebService with Apache CXF

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

    05-ApacheCamel-CXF-WebService

    05-ApacheCamel-CXF-WebService Apache Camel 集成 CXF组件,包含服务端、测试客户端

    Spring+CXF开发WebService

    Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构。它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的...

    Apache CXF2+Spring2.5轻松实现WebService

    NULL 博文链接:https://chilongxph.iteye.com/blog/510707

    WebService之CXF

    使用Apache CXF开发WebService,文档介绍了使用JDK开发WebService,然后介绍使用Apache XCF开发WebService,最后将CXF与Spring整合开发。

    Apache Cxf WebService整合Spring

    Apache Cxf WebService整合Spring 处理Map、非javabean式的复合类等CXF无法自动转化的类型 CXF为服务器端和客户端添加自定义拦截器进行权限检查验证并且控制台打印日志

    apache cxf_jar包

    java通过cxf实现webservice所需jar包。java通过cxf实现webservice所需jar包。

    Java分页算法以及一点Apache CXF webservice 资料

    Java分页算法以及一点CXF资料 Java分页算法以及一点Apache CXF webservice 资料

    基于Apache CXF构建SOA应用 随书源代码

    Apache CXF是一个开放源码的Web服务框架,提供了一个易于使用,用于开发Web Services标准为基础的编程模型。本书主要介绍Apache CXF在构建SOA架构各个方面的应用说明和编程案例。覆盖以下内容:基于JAX-WS规范和CXF...

    cxf做webservice接口

    Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构。它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的...

    apache-cxf-2.2.6.zip webservice cxf开发利器完整开发包

    webservice cxf apache-cxf-2.2.6 开发包

    使用Spring+CXF开发WebService.doc

    Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services 各种类型的Annotation。@WebService和@WebMethod是WSDL映射Annatotion。这些Annotation将描述Web ...

    springboot+cxf实现webservice示例

    &lt;groupId&gt;org.apache.cxf &lt;artifactId&gt;cxf-spring-boot-starter-jaxws &lt;version&gt;3.1.7 &lt;!-- CXF webservice --&gt; &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-starter-test ...

Global site tag (gtag.js) - Google Analytics