我是否一定需要第三方框架来实现基于 Java 的 REST 服务 (JSON)?

发布于 2025-01-04 06:18:20 字数 292 浏览 5 评论 0 原文

当然,JAX-RS 应该无需任何额外的框架即可工作,就像 JAX-WS 一样。 但在 JAX-WS 中,我只是在 POJO 上添加一些注释,用一行代码创建一个自托管服务,仅此而已。

我找不到任何教程或资源来展示如何使用 JAX-RS 执行相同的操作。几乎每个教程都使用 Jersey(或 Easyrest 等)并且至少使用 Maven。是否没有一种简单的方法来设置基于 Rest 的服务,就像使用 JAX-WS 一样?

谢谢

编辑:嗯,我认为如果没有这些框架,@Path 等注释就无法使用?我的日食无法引用/找到它们:(

Of course JAX-RS should work without any additional framework like JAX-WS also does.
But in JAX-WS, I just put some annotations on a POJO, create a self hosted service with one single line of code and that's it.

I can't find any tutorials or resources that show how to do the same with JAX-RS. Nearly every tutorial uses Jersey (or Easyrest etc.) and at least Maven. Isn't there an easy way to set up a Rest based service like it can be done with JAX-WS?

Thank you

edit: Hm, I think annotations like @Path etc. aren't available without these frameworks? My eclipse cannot reference/find them :(

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

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

发布评论

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

评论(2

夜声 2025-01-11 06:18:20

JAX-RS 是一个 API。 Jersey 和 RESTEasy 是它的实现。 Jersey 是 JAX-RS 的“参考”实现,因此经常出现在教程中(毕竟,需要一些 API 实现才能使用它)。

http://en.wikipedia.org/wiki/Java_API_for_RESTful_Web_Services

JAX-RS is an API. Jersey and RESTEasy are its implementations. Jersey, is the 'reference' implementation of JAX-RS, and therefore shows up frequently in tutorials (after all, one needs some implementation of the API to use it).

http://en.wikipedia.org/wiki/Java_API_for_RESTful_Web_Services

千秋岁 2025-01-11 06:18:20

可以轻松访问宁静的网络服务。您甚至可以使用:

URL url = new URL(docUrl);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

您可以使用该连接,就像在其他地方使用它一样。

Restful webservices can be easily accessed. You can even use:

URL url = new URL(docUrl);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

you can use the connection just like using it anywhere else.

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