1、JAXRSServerFactoryBean编程方式

访问方式:http://localhost:8080/cxf_spring_rest_server/ws/rest/student/querylist/001?_type=json

发布类:

public class StudentServer {
public static void main(String[] args) { //使用jaxrsServerFactoryBean发布rest服务
JAXRSServerFactoryBean jaxrsServerFactoryBean = new JAXRSServerFactoryBean();
//设置rest的服务地址
jaxrsServerFactoryBean.setAddress("http://127.0.0.1:12345/rest");
//设置服务对象
jaxrsServerFactoryBean.setServiceBean(new StudentServiceImpl());
//设置资源 对象,如果有多个pojo资源 对象中间以半角逗号隔开
jaxrsServerFactoryBean.setResourceClasses(StudentServiceImpl.class);
//发布rest服务
jaxrsServerFactoryBean.create(); }
}

接口类:

@WebService
@Path("/student")
public interface StudentService { //查询学生信息
@GET //http的get方法
@Path("/query/{id}")//id参数通过url传递
@Produces(MediaType.APPLICATION_XML)//设置媒体类型xml格式
public Student queryStudent(@PathParam("id")long id); //查询学生列表
@GET //http的get方法
@Path("/querylist/{type}")
@Produces({"application/json;charset=utf-8",MediaType.APPLICATION_XML})//设置媒体类型xml格式和json格式
//如果想让rest返回xml需要在rest的url后边添加?_type=xml,默认为xml
//如果想让rest返回json需要在rest的url后边添加?_type=json
public List<Student> queryStudentList(@PathParam("type") String type); }

实现类:

public class StudentServiceImpl implements StudentService {

    @Override
public Student queryStudent(long id) {
// 使用静态数据
Student student = new Student();
student.setId(id);
student.setName("张三");
student.setBirthday(new Date());
return student;
} @Override
public List<Student> queryStudentList(String type) {
// 使用静态数据
List<Student> list = new ArrayList<Student>();
Student student1 = new Student();
student1.setId(1000l);
student1.setName("张三");
student1.setBirthday(new Date()); Student student2 = new Student();
student2.setId(1000l);
student2.setName("张三");
student2.setBirthday(new Date()); list.add(student1);
list.add(student2);
return list;
} }

2、与spring整合

<!-- service -->
<bean id="studentService" class="cn.allan.ws.cxf.rest.service.StudentServiceImpl"/> <!-- 发布rest服务
使用jaxws:server和jaxws:endpoint可以发布服务
webservice地址=tomcat地址+cxf servlet的路径+/weather
-->
<jaxrs:server address="/rest">
<jaxrs:serviceBeans>
<ref bean="studentService"/>
</jaxrs:serviceBeans>
</jaxrs:server>

使用CXF开发JAX-RS类型的WebService的更多相关文章

  1. 用cxf开发restful风格的WebService

    我们都知道cxf还可以开发restful风格的webService,下面是利用maven+spring4+cxf搭建webService服务端和客户端Demo 1.pom.xml <projec ...

  2. CXF 开发 WebService

    什么是CXF: Apache CXF = Celtix + Xfire 支持多种协议: SOAP1.1,1.2 XML/HTTP CORBA(Common Object Request Broker ...

  3. 3.使用CXF开发webService

    CXF 简介 关于 Apache CXF Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache ...

  4. webservice原理及基于cxf开发的基本流程

    一.SOA和webservice SOA(service-Oriented Architecture)是面向服务的架构,是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的 ...

  5. struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例

    Cxf + Spring+ myeclipse+ cxf 进行  Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...

  6. 使用cxf开发webservice应用时抛出异常

    在使用cxf开发webservice应用时,报出了类似下面的错误 JAXB: [javax.xml.bind.UnmarshalException: unexpected element (uri:& ...

  7. Spring boot+CXF开发WebService

    最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...

  8. Spring boot+CXF开发WebService Demo

    最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...

  9. (二)使用CXF开发WebService服务器端接口

    CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它. CXF主页:http://cxf.apache.org/ 简介:百度百科 今天的话,主要是用CXF来开发下Web ...

  10. 【WebService】使用CXF开发WebService(四)

    CXF简介 Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.CXF 继承了 Celtix ...

随机推荐

  1. Keras Xception Multi loss 细粒度图像分类

    作者: 梦里茶 如果觉得我的工作对你有帮助,就点个star吧 关于 这是百度举办的一个关于狗的细粒度分类比赛,比赛链接: http://js.baidu.com/ 框架 Keras Tensorflo ...

  2. Vue2源码分析-逻辑梳理

    很久之前就看完vue1,但是太懒就一直没写博客,这次打算抽下懒筋先把自己看过了记录下来,否则等全部看完,估计又没下文了 看源码总需要抱着一个目的,否则就很难坚持下去,我并没做过vue的项目,我几乎很少 ...

  3. 如何查看appache的端口是否被占用

    win + R 快捷键输入 cmd 打开命令行. 输入 netstat -ano 查看端口使用情况 Ctrl + Shift + Esc 打开 windows 任务管理器,依次单击 [查看][ 选择列 ...

  4. hdu--1013--Digital Roots(字符串)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. WCF项目的架构设计

    本文将介绍以WCF开发项目为主的架构设计,主要从类库的分类和代码的结构. 下面将以一个WCF实例做具体的介绍.此项目底层是一个Windows Service,WCF服务Hosted在此Windows ...

  6. 基于Dubbo的压测调优实例

    不久前参与开发了一个基于dubbo分布式框架的底层账单系统,并实现了其中的一部分业务接口,目前需对这些接口进行压测,以评估生产环境所能承受的最大吞吐量.笔者以其中一个查询接口为例来回顾此次压测的整体流 ...

  7. SolrCloud(一)搭建Zookeeper

    搭建Zookeeper 三台服务器: AMouse: 192.168.3.201 BCattle : 192.168.3.202 Ctiger   : 192.168.3.203 一 下载Zookee ...

  8. 关于浏览器解析html全过程详解

    本人web前端菜鸟一枚,第一次在这里发博客梳理知识,知识都是从各地方查阅引用以及自己的理解得来,有什么错误的地方欢迎指正. DOM文档通常加载的步骤: 1.解析HTML结构. 2.加载外部脚本和样式表 ...

  9. vue.js + ajax 数据加载(纯新手get)

    似懂非懂的感觉下撸了一个小demo .(只是单纯的引用vue.js的小demo.)在实践中进步吧! 首先肯定要先看vue的文档,并且知道超超基础的小知识!!!奉上代码: HTML 部分: js的引用: ...

  10. .Net Core 2.0生态(4):Entity Framework Core 2.0 特性介绍和使用指南

    前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升级EF也发展到EF6.x,Entity Framework Core是一个支持跨平台的全新版本, ...