采用CXF+spring+restful创建一个web接口项目
这篇文章是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接口项目的更多相关文章
- Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目
Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...
- CXF 入门:创建一个基于WS-Security标准的安全验证(CXF回调函数使用,)
http://jyao.iteye.com/blog/1346547 注意:以下客户端调用代码中获取服务端ws实例,都是通过CXF 入门: 远程接口调用方式实现 直入正题! 以下是服务端配置 ==== ...
- 基于cxf开发restful风格的Web Service
一.写在前面 webservice一些简单的其他用法和概念,就不在这里赘述了,相信大家都可以在网上查到,我也是一个新手,写这篇文章的目的一方面是想记录自己成长的历程,另一方面是因为学习这个的时候花了点 ...
- 【Spring】创建一个Spring的入门程序
3.创建一个Spring的入门程序 简单记录 - Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)- Spring的基本应用 Spring与Spring MVC的 ...
- C#中自己动手创建一个Web Server(非Socket实现)
目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...
- Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址?
Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址? 访问URL: http://localhost:8090/firstapp/login 在eclipse集成的 ...
- spring cloud教程之使用spring boot创建一个应用
<7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...
- 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 创 ...
- 使用eclipse插件创建一个web project
使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...
随机推荐
- perl Exporter一些神奇写法
use base qw(Exporter); @JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_j ...
- FZOJ2110: Star
Problem Description Overpower often go to the playground with classmates. They play and chat on the ...
- 在WEB工程的web层中的编程技巧
本篇以看传智播客方立勋老师的<JDBC入门>之<实现客户关系管理案例>视频有感,从中提取方老师在设计管理系统的简单案例中对自己比较有用的部分,以便日后在开发过程中希望能有所帮助 ...
- Servlet的学习(三)
本篇接上一篇<Servlet的学习(二)> ,主要讲诉如何使用MyEclipse来开发Servlet,和导入Servlet所需要的源代码. 现在我们来创建一个web应用,就叫[myserv ...
- 关于在打包Jar文件时遇到的资源路径问题(二)
在关于<关于在打包Jar文件时遇到的资源路径问题(一)>中,以及描述了当资源与可执行JAr分离时的资源路径代码的编写问题,后来想了想,为什么将<Java核心技术卷一>中的程序1 ...
- goldengate 简单配置 oracle to oralce
做oracle时配置的,goldengate 是同步异构数据库最好的工具.这个是基于oracle to oracle 单向复制 添加增量复制进程 add extract process -- -- ...
- 深入研究Clang(四) Clang编译器的简单分析
作者:史宁宁(snsn1984) 首先我们确定下Clang编译器的详细内容和涵盖范围.之前在<LLVM每日谈之二十 Everything && Clang driver>中 ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- PySide——Python图形化界面
PySide——Python图形化界面 PySide——Python图形化界面入门教程(四) PySide——Python图形化界面入门教程(四) ——创建自己的信号槽 ——Creating Your ...
- WAS ND集群中的HTTP内存会话复制对Java应用程序序列化编程的要求
应用程序需要遵守的约定 在会话中没有自定义对象时,WAS 集群的 HTTP 会话内存复制特性成功地实现了高可用性,使用户在宕机过程中的会话信息没有丢失,操作没有受到任何影响. 在会话中包含自定义对象时 ...