使用 OkHttp 作为 Feign 客户端的 Maven 依赖项
当 okhttp 与 feign 一起使用时抛出以下依赖项,它会抛出 java.lang.NoClassDefFoundError: okhttp3/ConnectionPool 异常。
添加到项目的依赖项:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
以下代码显示了如何将 OkHttpClient 与 feign 一起使用:
// creating an instance of OkHttpClient
ConnectionPool pool = new ConnectionPool(1, 5, TimeUnit.MINUTES);
okhttp3.OkHttpClient client = new okhttp3.OkHttpClient.Builder()
.connectionPool(pool)
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
OkHttpClient okHttpClient = new OkHttpClient(client);
// creating a feign builder with OkHttp
Feign.builder()
.client(okHttpClient)
.target(clazz, properties.getBaseUrl());
我缺少解决 java.lang.NoClassDefFoundError: okhttp3/ConnectionPool? 的内容?
When okhttp used with feign throw below dependencies, it throws the java.lang.NoClassDefFoundError: okhttp3/ConnectionPool exception.
Dependencies Added to project:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
Here is the code shows how the OkHttpClient is used with feign:
// creating an instance of OkHttpClient
ConnectionPool pool = new ConnectionPool(1, 5, TimeUnit.MINUTES);
okhttp3.OkHttpClient client = new okhttp3.OkHttpClient.Builder()
.connectionPool(pool)
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
OkHttpClient okHttpClient = new OkHttpClient(client);
// creating a feign builder with OkHttp
Feign.builder()
.client(okHttpClient)
.target(clazz, properties.getBaseUrl());
What I'm missing to resolve java.lang.NoClassDefFoundError: okhttp3/ConnectionPool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论