使用 javax.ws.rs-api-2.1.1 设置超时时出错
Error setting timeout with javax.ws.rs-api-2.1.1
我正在通过 jax ws rs 为 restApi 客户端设置超时,我是这样实现的
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
clientBuilder.connectTimeout(10, TimeUnit.SECONDS);
clientBuilder.readTimeout(12, TimeUnit.SECONDS);
Client client = clientBuilder.build();
但是,这个剧照仍然抛出这个异常,我不知道原因
Exception in thread "main" java.lang.AbstractMethodError: javax.ws.rs.client.ClientBuilder.connectTimeout(JLjava/util/concurrent/TimeUnit;)Ljavax/ws/rs/client/ClientBuilder;
at weblogicrestfulapi.consumeRFApi.requestRestApi(consumeRFApi.java:74)
at weblogicrestfulapi.consumeRFApi.readResponseRestApi(consumeRFApi.java:96)
at weblogicrestfulapi.main.main(main.java:90)
C:\Users\medinajaim\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:53: Java returned: 1
希望有人能帮我解决这个问题,谢谢!
如果有人为此选择答案,我的解决方案基于 Deadron 和 Paul 的评论,我发现这个 link 解决了 javax.ws.rs-api-2.1 的依赖关系.1 如果您在企业容器之外
对我来说,它只适用于添加这两个依赖项:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
我正在通过 jax ws rs 为 restApi 客户端设置超时,我是这样实现的
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
clientBuilder.connectTimeout(10, TimeUnit.SECONDS);
clientBuilder.readTimeout(12, TimeUnit.SECONDS);
Client client = clientBuilder.build();
但是,这个剧照仍然抛出这个异常,我不知道原因
Exception in thread "main" java.lang.AbstractMethodError: javax.ws.rs.client.ClientBuilder.connectTimeout(JLjava/util/concurrent/TimeUnit;)Ljavax/ws/rs/client/ClientBuilder;
at weblogicrestfulapi.consumeRFApi.requestRestApi(consumeRFApi.java:74)
at weblogicrestfulapi.consumeRFApi.readResponseRestApi(consumeRFApi.java:96)
at weblogicrestfulapi.main.main(main.java:90)
C:\Users\medinajaim\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:53: Java returned: 1
希望有人能帮我解决这个问题,谢谢!
如果有人为此选择答案,我的解决方案基于 Deadron 和 Paul 的评论,我发现这个 link 解决了 javax.ws.rs-api-2.1 的依赖关系.1 如果您在企业容器之外
对我来说,它只适用于添加这两个依赖项:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>