使用dubbox开发REST应用
新建项目,添加Maven支持。
在pom.xml中添加依赖。
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency> <!-- 如果要使用json序列化 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.7.Final</version>
</dependency> <!-- 如果要使用xml序列化 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.7.Final</version>
</dependency> <!-- 如果要使用netty server -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty</artifactId>
<version>3.0.7.Final</version>
</dependency> <!-- 如果要使用Sun HTTP server -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jdk-http</artifactId>
<version>3.0.7.Final</version>
</dependency> <!-- 如果要使用tomcat server -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>8.0.11</version>
</dependency>
新建接口
public interface UserService {
public ArrayList<String> sayHello(String uid);
}
新建接口实现类
@Path("rest")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public class UserServiceImpl implements UserService {
@GET
@Path("/sayHello/{uid}")
@Override
public ArrayList<String> sayHello(@PathParam("uid")String uid) {
ArrayList<String> x= new ArrayList<String>();
x.add("xxxx");
return x;
}
}
新建dubbox配置文件
<dubbo:application name="platform" owner="programmer" organization="dubbox"/> <dubbo:registry address="zookeeper://localhost:2181" /> <dubbo:protocol name="rest" port="8081" server="tomcat" ></dubbo:protocol> <dubbo:service interface="rest.UserService" ref="userServiceImpl" /> <bean id="userServiceImpl" class="rest.UserServiceImpl"></bean>
新建启动类启动dubbox的rest服务
System.out.println("准备启动");
ClassPathXmlApplicationContext ap=new ClassPathXmlApplicationContext("applicationContext_dubbo.xml");
UserService userSrv=(UserService) ap.getBean("userServiceImpl");
System.out.println("启动DemoServiceProvider完成");
userSrv.sayHello("xushuai");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
验证:启动zookeeper,启动应用。
通过浏览器访问rest接口。

使用dubbox开发REST应用的更多相关文章
- dubbox开发rest+json指南【转】
http://dangdangdotcom.github.io/dubbox/rest.html 目录 概述 REST的优点 应用场景 快速入门 标准Java REST API:JAX-RS简介 RE ...
- dubbo环境搭建与tomcat集成、DEMO示例、常见问题(最完整版本、带管理控制台、监控中心、zookeeper)
以windows为例,linux基本相同,开发环境一般linux,个人环境一般windows(如果不开额外vm的话). 示例以dubbo官方自带demo为例子,进行整合和稍加修改测试. 0.dubbo ...
- Dubbox服务的消费方开发
开发步骤: (1)创建Maven工程(WAR)dubboxdemo-web ,在pom.xml引入依赖 ,同“dubboxdemo-service”工程.区别就是把tomcat插件的运行端口改为808 ...
- Dubbox中开发REST风格的远程调用
转载: http://zyg345646335.iteye.com/blog/2208899
- Dubbox服务的提供方开发
(1)创建Maven工程(WAR)dubboxdemo-service ,在pom.xml中引入依赖 <project xmlns="http://maven.apache.org/ ...
- spring/spring boot/spring cloud开发总结
背景 针对RPC远程调用,都在使用dubbo.dubbox等,我们也是如此.由于社区暂停维护.应对未来发展,我们准备尝试新技术(或许这时候也不算什么新技术了吧),选择使用了spring ...
- dubbox 增加google-gprc/protobuf支持
好久没写东西了,今年实在太忙,基本都在搞业务开发,晚上来补一篇,作为今年的收官博客.google-rpc 正式发布以来,受到了不少人的关注,这么知名的rpc框架,不集成到dubbox中有点说不过去. ...
- dubbox
github源码: https://github.com/dangdangdotcom/dubbox maven中央仓: 无 获取分支 git clone -b dubbox-2.8.4 https: ...
- dubbox新特性介绍
dubbx是当当网对原阿里dubbo2.x的升级,并且兼容原有的dubbox.其中升级了zookeeper和spring版本,并且支持restfull风格的远程调用. dubbox git地址: h ...
随机推荐
- 弄技术要弄通-公司reis的pub/sub怎么使用的呢?
Pub/Sub in Redis using PHP Posted on November 14, 2011by xmeng I would like to put an example togeth ...
- 在学习c++过程中,总结类的三个用户以及使用权限,感觉非常实用
首先我们需要知道类的三个用户分别是:类的实现者,类的普通用户和类的继承者(派生类),接下来分别讲解这几种用户的区别. 1 .类的实现者:顾明思议,就是类的设计者,拥有最大的权限,可以访问类中任何权限的 ...
- CSS的两个class选择器紧挨在一起
有一段HTML代码: <a class="glyphicons white no-js cogwheel" href="#" target="_ ...
- 【hadoop】ssh localhost 免密码登陆(图解)
假设系统中有用户test,属于用户组test, 1. 首先确认能否不输入口令就用ssh登录localhost: $ ssh localhost 输出如下所示: 2. 如果不输入口令就无法用ssh登陆l ...
- ELF和a.out文件格式的比较
本文讨论了 UNIX/LINUX 平台下三种主要的可执行文件格式:a.out(assembler and link editor output 汇编器和链接编辑器的输出).COFF(Common Ob ...
- Visual C++ 2010入门教程
<Visual C++ 2010入门教程>系列一:关于Visual Studio.VC和C++的那些事 作者:董波 日期:2010.6.14 写在前面 在我还在上学的时候,我选择了C+ ...
- [TJOI2016&HEOI2016] 排序
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4552 [算法] 首先 , 二分答案x , 将比x小的数看作1,比x大的数看作0 然后 ...
- VS2013在右键菜单添加命令插件开发
一.选择Visual Studio Package模板建立插件项目 由于此功能需要在右键菜单上添加命令,所以选择Visual Studio Package模板,根据模板向导步骤插件项目,在Select ...
- win7上安装macaca的报错问题
macaca网上的各种教程中,都建议使用淘宝源安装macaca,使用淘宝源就需要先安装cnpm,在win7上切换到淘宝源安装cnpm后(npm install -g cnpm --registry=h ...
- 2-17 numpy模块使用
#CURD import numpy as np data1 = np.array([1,2,3,4,5]) print(data1) data2 = np.array([[1,2], [3,4]]) ...