[英]jersey-client version mismatch in Spring Boot
For creating a REST Client am using the below dependency in Spring Boot: 要创建REST客户端,请在Spring Boot中使用以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
Which in turn downloads the jersey-client-2.23.1.jar. 依次下载jersey-client-2.23.1.jar。 My code for request builder is as below: 我的请求构建器代码如下:
Client client = ClientBuilder.newClient();
WebTarget targetUrl = client.target("Some URL").path(userid)
.path("Some String");
Builder requestBuilder = targetUrl.request(MediaType.APPLICATION_JSON);
JsonParser parser = new JsonParser();
JsonArray objArray = (JsonArray) parser.parse(requestBuilder.get(String.class));
However I am getting the below exception in line number 3 of the above code: 但是我在上面的代码的第3行中得到了下面的异常:
java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:336) ~[jersey-client-2.23.1.jar:na]
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:221) ~[jersey-client-2.23.1.jar:na]
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:59) ~[jersey-client-2.23.1.jar:na]
I saw few solution that it is due to version mismatch. 我看到很少的解决方案是由于版本不匹配所致。 So, I tried to added a lower version dependency: 因此,我尝试添加一个较低的版本依赖项:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.2</version>
</dependency>
But spring boot is not considering this version of jersey-client. 但是spring boot并没有考虑这个版本的jersey-client。 Is there any way out so that I can solve the issue? 有什么办法可以解决这个问题吗?
EDIT 1: As mentioned in the first answer I used mvn dependency:tree and found 2 different version of jersey client available. 编辑1:如第一个答案中所述,我使用了mvndependency:tree,发现有2个不同版本的jersey客户端可用。 One is compile time and one is run time: 一种是编译时,一种是运行时:
[INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:1.4.0.RELEASE:compile
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:2.23.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-common:jar:2.23.1:compile
[INFO] | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.23.1:compile
[INFO] | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:2.23.1:compile
and 和
[INFO] +- some.project.specific:jar:1.1.5.RELEASE:compile
[INFO] | +- some.project.specific:jar:1.4.10:compile
[INFO] | | +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
I tried to exclude version 2.23.1 as below. 我尝试排除以下版本2.23.1。 Still it is including the jar. 它仍然包括罐子。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client-2.23.1</artifactId>
</exclusion>
</exclusions>
</dependency>
Check other dependencies on your project, try running mvn dependency:tree
. 检查项目上的其他依赖项,尝试运行mvn dependency:tree
。 Probably you have some other dependency to jersey 1.XX version, you should exclude it to keep just the 2.23.1. 可能您对jersey 1.XX版本还有其他依赖性,您应该排除它以仅保留2.23.1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.