簡體   English   中英

從 Jersey 1.x 升級到 2.x

[英]Upgrading from Jersey 1.x to 2.x

請注意:有與此類似的問題,但沒有什么可以使這完全成為騙局。


我目前有以下 Gradle 依賴項:

dependencies {
    compile "com.sun.jersey.contribs:jersey-apache-client4:1.18.1"
    compile "com.sun.jersey:jersey-client:1.18.1"
    compile "com.sun.jersey:jersey-core:1.18.1"
    compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2"
    compile "org.apache.httpcomponents:httpclient:4.3.2"
    compile "org.slf4j:jcl-over-slf4j:1.7.7"
}

我想將這些升級到 Jersey 的2.21版本,但是:

  • 似乎 groupName 現在是org.glassfish.jersey.core而不是com.sun.jersey
  • 似乎 Jersey-Client 現在不需要明確聲明 Jersey-Core(Jersey-Core 似乎不再作為 JAR 存在)
  • Jersey Apache 4 客戶端 ( jersey-apache-client4 ) 似乎不存在於 2.x 領域

所以我問,我所有的2.21依賴項應該是什么? 這些天,那個 Jersey/Apache 客戶端藏在哪里?

對於澤西島客戶,您只需要

compile 'org.glassfish.jersey.core:jersey-client:2.21'

jersey-core不再存在,盡管它可以被認為類似於jersey-common 但是你不必擔心這個。 jersey-client把它拉進來。

至於 Apache,Jersey 2 使用連接器提供程序。 請參閱客戶端傳輸連接器 你想要的是 Apache 連接器

compile 'org.glassfish.jersey.connectors:jersey-apache-connector:2.21'

然后只需配置Client

ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.register(JacksonJsonProvider.class);
Client client = ClientBuilder.newClient(config);

您還應該擺脫當前的httpclient依賴項。 jersey-apache-connector將其拉入。

有關新客戶端 API 的一般用法,請參閱第 5 章。客戶端 API


您的問題標題非常籠統,但從您的依賴項來看,您只是在嘗試實現客戶端。 但是對於想要實現服務器的任何其他人,他們可以查看

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM