实现 Java REST Web 服务的最简单框架

发布于 2024-08-06 02:52:36 字数 1536 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

み青杉依旧 2024-08-13 02:52:37

您可以查看 CXF JAX-RS 实现。有关其功能的完整列表,请查看 JAX-RS 的 CXF 网站
该项目背后的社区似乎非常活跃(2013 年 7 月)。 CXF 邮件列表 中每天的消息数量就可以说明这一点。

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.

沫雨熙 2024-08-13 02:52:37

我可以推荐 Apache wink,一个仍处于孵化模式的新框架,但非常成熟且高质量。

http://incubator.apache.org/wink/

它实现了 JAX-RS 规范,它既有客户又有客户用于 REST 开发的服务器框架。
Apache 是这个项目的后盾 - 这始终是一个好兆头(也是一个好的许可证 :-) )

我最喜欢这个框架的地方是与 Spring 的直观集成,如果您希望您的框架能够轻松配置和扩展,那么它非常有用。

I can recommend Apache wink, a new framework still in incubation mode, but very mature and high quality.

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 :-) )

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.

二货你真萌 2024-08-13 02:52:37

更新:Xydra Restless 不再维护 +++ 如果您在 Goolge AppEngine 发布“预留实例”功能之前使用它们,您可能会考虑 Xydra Restless 功能很少,但加载速度很快。

UPDATE: Xydra Restless is not longer maintained +++ If your are using Goolge AppEngine before they release a "reserve instance" feature, you might consider Xydra Restless which has few features but loads fast.

浪漫之都 2024-08-13 02:52:37

我最喜欢的是 Spring MVC,两者都支持,客户端和服务器端......而且你也有Android支持=)

例如,你可以看到Spring Android的示例 这里

My favourite is Spring MVC, you have support for both, client and server side... And you have Android support too =)

For example, you can see a example of Spring Android here

零度° 2024-08-13 02:52:36

Jersey 对两者来说都非常容易。要编写 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";
    }
}

对于客户端:

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

Jersey is really easy for both. To write web services, you use annotations:

@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
我一直都在从未离去 2024-08-13 02:52:36

Restlet 听起来应该提供您正在寻找的内容:

  • 支持客户端和服务器(在相对对称的 api 中) )
  • 智能 url 绑定
  • mime 类型理解(给定接受的 mime 类型,它会询问您的资源在该类型中的表示)
  • 支持 JAX-RS 注释(就像 Jersey)

Restlet sounds like it should provide what you're looking for:

  • 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)
素染倾城色 2024-08-13 02:52:36

也可以看看dropwizard

Take a look at dropwizard too.

空心空情空意 2024-08-13 02:52:36

Restlet 在其 2.0 版本中还支持客户端和服务器端的注释。 JAX-RS API 也作为扩展受到支持。

这是服务器端的一个简单示例:

public class HelloWorldResource extends ServerResource {

    @Get
    public String represent() {
        return "hello, world";
    }

}

在客户端:

// Outputting the content of a Web page  
new ClientResource("http://www.restlet.org").get().write(System.out);

有关更多文档,检查此页面

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.

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.

等往事风中吹 2024-08-13 02:52:36

JBoss 的新 RESTEasy 库。自首次推出以来,它似乎正在快速发展。我不知道这是否有好处;它在我的“查看”清单上。

There's JBoss' new RESTEasy library. It appears to be under rapid development since its initial launch. I've no idea if it's any good; it's on my 'check it out' list.

爱,才寂寞 2024-08-13 02:52:36

我个人没有使用过它,但与我合作的一些团队正在使用 Spring 3 MVC。 Spring 3 中的 REST:@MVC看起来是一篇很好的博客文章概述。 RESTful 功能包括“URI 模板”、“内容协商”、“HTTP 方法转换”、“ETag 支持”等。

编辑:另外,请参阅这个问题:谁能推荐一个基于MVC并支持REST的Java Web框架吗?

I haven't used it personally but some teams that I work with are using Spring 3 MVC. REST in Spring 3: @MVC looks like a good blog post overview. The RESTful features include "URI Templates", "Content Negotiation", "HTTP Method Conversion", "ETag support" and more.

Edit: Also, see this question: Can anyone recommend a Java web framework that is based on MVC and supports REST ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文