实现 Java REST Web 服务的最简单框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1495813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easiest frameworks to implement Java REST web services
提问by Marcus Leon
What are the best frameworks for implementing both client and server REST frameworks in Java? I've been struggling a little to find an easy to use solution.
在 Java 中实现客户端和服务器 REST 框架的最佳框架是什么?我一直在努力寻找一个易于使用的解决方案。
Update: Both Jersey and Restlet seem like good options. We'll probably use Restlet but we'll experiment with both.
更新: Jersey 和 Restlet 似乎都是不错的选择。我们可能会使用 Restlet,但我们会同时试验两者。
采纳答案by Stephen
Restletsounds like it should provide what you're looking for:
Restlet听起来应该提供您正在寻找的内容:
- Support for client and server (in a relatively symmetric api)
- Smart url binding
- mime type understanding (given accepted mime types, it will ask your resources for their representation in that type)
- Supports JAX-RS annotations (just like Jersey)
- 支持客户端和服务器(在一个相对对称的 api 中)
- 智能网址绑定
- mime 类型理解(给定接受的 mime 类型,它会询问您的资源在该类型中的表示)
- 支持 JAX-RS 注释(就像 Jersey)
回答by Droo
Jerseyis really easy for both. To write web services, you use annotations:
泽西岛对两者来说都很容易。要编写 Web 服务,请使用注释:
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String helloWorld() {
// Return some cliched textual content
return "Hello World";
}
}
For a client:
对于客户:
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/helloworld");
String s = webResource.get(String.class);
System.out.println(s); // prints Hello World
回答by Jerome Louvel
Restlet also support annotations in its 2.0 version, both on the client and server-side. The JAX-RS API is also supported as an extension.
Restlet 还在其 2.0 版本中支持客户端和服务器端的注释。还支持 JAX-RS API 作为扩展。
Here is a simple example for server-side:
这是服务器端的一个简单示例:
public class HelloWorldResource extends ServerResource {
@Get
public String represent() {
return "hello, world";
}
}
On the client-side:
在客户端:
// Outputting the content of a Web page
new ClientResource("http://www.restlet.org").get().write(System.out);
For further documentation, check this page.
如需更多文档,请查看此页面。
回答by SteveD
回答by Kevin Hakanson
I haven't used it personally but some teams that I work with are using Spring 3 MVC. REST in Spring 3: @MVClooks like a good blog post overview. The RESTful features include "URI Templates", "Content Negotiation", "HTTP Method Conversion", "ETag support" and more.
我个人没有使用过它,但与我合作的一些团队正在使用 Spring 3 MVC。 Spring 3 中的 REST:@MVC看起来像是一篇不错的博客文章概述。RESTful 特性包括“URI 模板”、“内容协商”、“HTTP 方法转换”、“ETag 支持”等。
Edit: Also, see this question: Can anyone recommend a Java web framework that is based on MVC and supports REST ?
编辑:另外,请参阅这个问题: 谁能推荐一个基于 MVC 并支持 REST 的 Java Web 框架?
回答by LiorH
I can recommend Apache wink, a new framework still in incubation mode, but very mature and high quality.
我可以推荐 Apache wink,一个仍处于孵化模式的新框架,但非常成熟和高质量。
http://incubator.apache.org/wink/
http://incubator.apache.org/wink/
It implements the JAX-RS specification, it has both client & server framework for REST development. Apache is standing behind this project - that's always a good sign (and a good license :-) )
它实现了 JAX-RS 规范,具有用于 REST 开发的客户端和服务器框架。Apache 支持这个项目——这总是一个好兆头(也是一个好的许可 :-))
What I love most about this framework is the intuitive integration with Spring, it's very useful if you want your framework to be easily configured and extended.
我最喜欢这个框架的地方是它与 Spring 的直观集成,如果您希望您的框架易于配置和扩展,它非常有用。
回答by Dr. Max V?lkel
UPDATE: Xydra Restless is not longer maintained +++ If your are using Goolge AppEngine before they release a "reserve instance" feature, you might consider Xydra Restlesswhich has few features but loads fast.
更新:不再维护 Xydra Restless +++ 如果您在 Goolge AppEngine 发布“保留实例”功能之前使用它们,您可能会考虑Xydra Restless,它功能很少但加载速度很快。
回答by i000174
You could take a look at the CXF JAX-RS implementation. For complete list of its features check the CXF web site for JAX-RS. The community behind the project seems to be very active (July 2013). An indication of that is the number of messages per day in the CXF mailing lists.
您可以查看 CXF JAX-RS 实现。有关其功能的完整列表,请查看JAX-RS的CXF 网站。该项目背后的社区似乎非常活跃(2013 年 7 月)。CXF 邮件列表中每天的消息数就是一个指示 。
回答by Javier Manzano
回答by joshua
Take a look at dropwizardtoo.
也看看dropwizard。