这篇文章是http://blog.csdn.net/zxnlmj/article/details/28880303下面,加入的基础上的restful特征

1、参加restful必jar包裹

jsr311-api-1.0.jar
CXF与JAX-RS版本号相应问题,參考自:http://bioubiou.iteye.com/blog/1866871
CXF支持REST风格的Web服务:JAX-RS2.0(JSR-339)和JAX-RS1.1(JSR-311)的Java API。
CXF2.7.0支持JAX-RS2.0(不包含clientAPI如今 - 引入的新功能。但注意CXFclientAPI已经更新,支持新的过滤器,拦截器,异常类和响应API,再加上client的异步调用API)。 CXF2.6.x版本号,在2.5.x。2.4.x和2.3.x的支持JSR-311 API1.1和JAX-RS1.1 TCK符合。 CXF2.2.x的支持JSR-311 API1.0和JAX-RS1.0 TCK标准。
CXF的2.1.x支持JSR-311 API0.8。

本文选择cxf-2.4.2.jar与jsr311-api-1.0.jar

2、开发restful服务

新建RestfulRegeditService.java接口

package zxn.ws.service;

import java.io.IOException;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType; @Path(value = "/")
public interface RestfulRegeditService { @POST
@Path("/regedit")
@Consumes(MediaType.APPLICATION_JSON)
public String regedit(String username, String password) throws IOException; }

新建RestfulRegeditServiceImpl.java接口

package zxn.ws.service.impl;

import java.io.IOException;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo; import zxn.ws.service.RestfulRegeditService; @Path(value = "/")
public class RestfulRegeditServiceImpl implements RestfulRegeditService { @Context
private UriInfo uriInfo; @Context
private Request request; @POST
@Path("/regedit")
@Produces(MediaType.APPLICATION_JSON)
public String regedit(String username, String password) throws IOException {
return "";
}
}

3、改动spring配置文件applicationContext.xml(粗体部分为需加入的)

<?xml version="1.0"?>

<beans xmlns="http://www.springframework.org/schema/b<span style="background-color: rgb(255, 255, 0);">eans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc</span>e" xmlns:aop="http://www.springframework.org/schema/aop"

    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

    xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd


                        http://www.springframework.org/schema/aop

                        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd


                        http://www.springframework.org/schema/context

                        http://www.springframework.org/schema/context/spring-context-3.0.xsd


                        http://www.springframework.org/schema/tx

                        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.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-servlet.xml" />



    <!-- webservice配置 ,myeclipse检測到此处有错没影响-->

    <jaxws:endpoint id="regeditService" implementor="zxn.ws.service.RegeditServiceImpl" address="/Regedit" />



<bean id="restfulRegeditService" class="zxn.ws.service.impl.RestfulRegeditServiceImpl" />

<!--restful服务 -->

    <jaxrs:server id="restServiceContainer" address="/regedit">

        <jaxrs:serviceBeans>

            <ref bean="restfulRegeditService" />

        </jaxrs:serviceBeans>

        <jaxrs:extensionMappings>

            <entry key="json" value="application/json" />

            <entry key="xml" value="application/xml" />

        </jaxrs:extensionMappings>

        <jaxrs:languageMappings>

            <entry key="en" value="en-gb" />

        </jaxrs:languageMappings>

    </jaxrs:server></strong>

</beans>

4、部署到tomcat,执行。成功。界面下图:

5、源码地址下载:http://download.csdn.net/detail/zxnlmj/7458403

版权声明:本文博主原创文章,博客,未经同意不得转载。

采用CXF+spring+restful创建一个web接口项目的更多相关文章

  1. Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目

    Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...

  2. CXF 入门:创建一个基于WS-Security标准的安全验证(CXF回调函数使用,)

    http://jyao.iteye.com/blog/1346547 注意:以下客户端调用代码中获取服务端ws实例,都是通过CXF 入门: 远程接口调用方式实现 直入正题! 以下是服务端配置 ==== ...

  3. 基于cxf开发restful风格的Web Service

    一.写在前面 webservice一些简单的其他用法和概念,就不在这里赘述了,相信大家都可以在网上查到,我也是一个新手,写这篇文章的目的一方面是想记录自己成长的历程,另一方面是因为学习这个的时候花了点 ...

  4. 【Spring】创建一个Spring的入门程序

    3.创建一个Spring的入门程序 简单记录 - Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)- Spring的基本应用 Spring与Spring MVC的 ...

  5. C#中自己动手创建一个Web Server(非Socket实现)

    目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...

  6. Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址?

    Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址? 访问URL:  http://localhost:8090/firstapp/login 在eclipse集成的 ...

  7. spring cloud教程之使用spring boot创建一个应用

    <7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...

  8. 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】

    Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...

  9. 使用eclipse插件创建一个web project

    使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...

随机推荐

  1. 《UNIX环境高级编程》笔记--read函数,write函数,lseek函数

    1.read函数 调用read函数从文件去读数据,函数定义如下: #include <unistd.h> ssize_t read(int filedes, void* buff, siz ...

  2. HTTPS的学习

    HTTPS的学习总结   HTTPS学习总结 简述 HTTPS对比HTTP就多了一个安全层SSL/TLS,具体就是验证服务端的证书和对内容进行加密. 先来看看HTTP和HTTPS的区别 我用AFN访问 ...

  3. 11661 - Burger Time?

      Burger Time?  Everybody knows that along the more important highways there are countless fast food ...

  4. [置顶] oracle 快速查询数据库各种信息、及转换对应java代码

    1 查询表中数据量 select 'select '||''''||t.TABLE_NAME||''''||' as table_name, count(*) from '|| t.TABLE_NAM ...

  5. 从头学起android&lt;AudioManager 声音编辑器.五十.&gt;

    我们用android经常使用的时候,手机的声音增大和缩小操作.在设定场景模式,它往往使用静音和振动运行,这通常是AudioManager来控制的. 今天我们就来看一下AudioManager 的使用. ...

  6. 《学习opencv》笔记——矩阵和图像处理——cvMinManLoc,cvMul,cvNot,cvNorm and cvNormalize

    矩阵和图像的操作 (1)cvMinManLoc函数 其结构 void cvMinMaxLoc(//取出矩阵中最大最小值 const CvArr* arr,//目标矩阵 double* min_val, ...

  7. LCD显示--Ht1621b芯片显示屏驱动

    Ht1621b芯片显示屏驱动 关于HT1621b芯片的具体信息能够參考数据手冊上的内容:百度文库HT1621b中文资料 CS : 片选输入接一上拉电阻当/CS 为高电平读写HT1621的数据和命令无效 ...

  8. ExtJs4 笔记(3) Ext.Ajax 对ajax的支持

    本篇主要介绍一下ExtJs常用的几个对JS语法的扩展支持,包括Ajax封装,函数事件操作封装,还有扩展的常用函数等.Ajax服务端交互式操作是提交到.NET MVC.后续服务端交互都采用这一方式实现. ...

  9. C语言之基本算法35—数组上三角之积 主对角之积 副对角之积

    //数组算法 /* ============================================================= 题目:求四阶矩阵上三角之积.主对角之积,副对角之积: 如 ...

  10. cocos2dx--两个场景切换各函数调用顺序

    场景A切换到场景B,有切换特效 调用顺序例如以下:(AAABABABA) A:构造函数 A:onEnter A:onEnterTransitionDidFinish B:构造函数 A:onExitTr ...