我如何从Jersey 1.0迁移到Jersey 2.0? [英] How do I migrate from Jersey 1.0 to Jersey 2.0?

查看:250
本文介绍了我如何从Jersey 1.0迁移到Jersey 2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试升级到Jersey 2.0,但遇到了很多麻烦,因为Jersey的groupIds和artifactIds已完全更改,并且在

I'm trying to upgrade to Jersey 2.0 and I'm having a lot of trouble because the groupIds and artifactIds of Jersey have completely changed and I can't find a migration plan in the Jersey docs.

这是我的pom.xml过去的样子,并且可以很好地编译:

Here's what my pom.xml used to look like, and this compiled fine:

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.17</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.17</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server-linking</artifactId>
            <version>1.17.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.17.1</version>
        </dependency>

这些应更改为什么? 这个无关的StackOverflow问题很有帮助,但我在找东西时遇到了麻烦就像@Ref注释移到的位置.

What should these be changed to? This unrelated StackOverflow question was somewhat helpful, but I'm having trouble finding things like where the @Ref annotation moved to.

  1. 似乎@Ref不再存在或至少文档中不再提及.现在,您使用UriBuilder.
  2. 我在文档中找到了一个非常有用的部分,可以回答我的问题专家问题.
  3. HTTPBasicAuthFilter已重命名为HttpBasicAuthFilter.注意大写.
  4. Client client = Client.create();已成为Client client = ClientBuilder.newClient();
  5. 此:

  1. It seems that @Ref no longer exists or at least it's not mentioned in the documentation anymore. Now you use a UriBuilder.
  2. I found a very helpful section in the documentation that answers my maven issues.
  3. The HTTPBasicAuthFilter has been renamed to HttpBasicAuthFilter. Notice the capitalization.
  4. Client client = Client.create(); has become Client client = ClientBuilder.newClient();
  5. This:

    String json = client
        .resource(getBaseUrl() + url)
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .get(String.class);

已成为

String json = client
        .target(getBaseUrl())
        .path(url)
        .request(MediaType.APPLICATION_JSON_TYPE)
        .get(String.class);

推荐答案

您不知道.

Jersey 2.0缺少Jersey 1.0的许多功能.与提交者会告诉您的相反,有些事情现在根本无法实现(例如,Guice,Spring集成).事情似乎在表面上起作用,但是一旦深入研究,您会发现很多功能仍然无法使用.

Jersey 2.0 is missing a lot of functionality from Jersey 1.0. Contrary to what the committers will tell you, some things are plain impossible to implement right now (e.g. Guice, Spring integration). Things appear to work on the surface, but once you dig in deeper you will find a lot of features are still broken.

许多1.x插件在2.x中不存在,主要是由于上述损坏.

Many of the 1.x plugins do not exist in 2.x, mainly because of the aforementioned breakage.

鉴于此,我建议在可预见的将来推迟Jersey 2.x的使用.希望提交者在来年将其清除.

In light of this, I suggest a holding off on Jersey 2.x for the foreseeable future. Hopefully the committers will clean this up in the coming year.

这篇关于我如何从Jersey 1.0迁移到Jersey 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆