使用CXF开发JAX-RS类型的WebService
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的更多相关文章
- 用cxf开发restful风格的WebService
我们都知道cxf还可以开发restful风格的webService,下面是利用maven+spring4+cxf搭建webService服务端和客户端Demo 1.pom.xml <projec ...
- CXF 开发 WebService
什么是CXF: Apache CXF = Celtix + Xfire 支持多种协议: SOAP1.1,1.2 XML/HTTP CORBA(Common Object Request Broker ...
- 3.使用CXF开发webService
CXF 简介 关于 Apache CXF Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache ...
- webservice原理及基于cxf开发的基本流程
一.SOA和webservice SOA(service-Oriented Architecture)是面向服务的架构,是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的 ...
- struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例
Cxf + Spring+ myeclipse+ cxf 进行 Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...
- 使用cxf开发webservice应用时抛出异常
在使用cxf开发webservice应用时,报出了类似下面的错误 JAXB: [javax.xml.bind.UnmarshalException: unexpected element (uri:& ...
- Spring boot+CXF开发WebService
最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...
- Spring boot+CXF开发WebService Demo
最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...
- (二)使用CXF开发WebService服务器端接口
CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它. CXF主页:http://cxf.apache.org/ 简介:百度百科 今天的话,主要是用CXF来开发下Web ...
- 【WebService】使用CXF开发WebService(四)
CXF简介 Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.CXF 继承了 Celtix ...
随机推荐
- [学习笔记] Splay Tree 从入门到放弃
前几天由于出行计划没有更博QwQ (其实是因为调试死活调不出来了TAT我好菜啊) 伸展树 伸展树(英语:Splay Tree)是一种二叉查找树,它能在O(log n)内完成插入.查找和删除操作.它是由 ...
- Linux下 两台机器文件/文件夹 相互拷贝
Linux下 两台机器文件/文件夹 相互拷贝 设有两台机器 :A:*.101及 B:*.102. 把A下的.temp/var/a.txt拷贝到B机器的/text/目录下: 进入B机器:scp root ...
- Docker Registry
前言 上一篇文章讲了Docker Machine实现多主机Docker节点的管理.本文讲解如何实现Docker Registry,其实这个在第一篇Docker入门一文中已经简单介绍,本文仅是对一些细节 ...
- webpack学习--创建一个webpack打包流程
创建一个webpack打包流程 首先安装webpack插件 mkdir webpack-demo && cd webpack-demo npm init -y npm install ...
- NYOJ--1236--挑战密室(第八届河南省程序设计大赛)
挑战密室 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 R组织的特工Dr. Kong 为了寻找丢失的超体元素,不幸陷入WTO密室.Dr. Kong必须尽快找到解锁密 ...
- Section 1.1 Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. TheseUFOs often com ...
- 自定义MySQL函数
1.MySQL创建函数语法: CREATE [DEFINER = { user | CURRENT_USER }] FUNCTION sp_name ([func_parameter[,...]]) ...
- 总结jq的一些特效
Jquery代码总结 1.轮播图: <script src="jquery-1.8.3.min.js"></script><script> ...
- Linux的nginx环境的vue 部署
1.使用WebStrom编程好的vue 进入到Terminal运行npm run build 2.使用WinSCP进入到nginx 目录配置文件下面,找到nginx.conf文件: ...
- 云端TensorFlow读取数据IO的高效方式
低效的IO方式 最近通过观察PAI平台上TensoFlow用户的运行情况,发现大家在数据IO这方面还是有比较大的困惑,主要是因为很多同学没有很好的理解本地执行TensorFlow代码和分布式云端执行T ...