java.lang.NoSuchMethodError:okio.BufferedSource.rangeEquals(JLokio / ByteString;)Z

问题描述 投票:3回答:2

我正在集成Outlook API和进行HTTP调用我正在使用Retrofit版本2.3.0和okHttp3版本3.9.1。但是,当我正在进行HTTP呼叫时,例如:

 // Create a logging interceptor to log request and responses
  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel( HttpLoggingInterceptor.Level.BODY );

  OkHttpClient client = new OkHttpClient.Builder().addInterceptor( interceptor ).build();

  // Create and configure the Retrofit object
  Retrofit retrofit = new Retrofit.Builder().baseUrl( authority ).client( client ).addConverterFactory( JacksonConverterFactory.create() ).build();

  // Generate the token service
  TokenService tokenService = retrofit.create( TokenService.class );

  try
  {
     return tokenService.getAccessTokenFromAuthCode( tenantId, getAppId(), getAppPassword(), "authorization_code", authCode, getRedirectUrl() ).execute().body();
  }
  catch ( IOException e )
  {
     TokenResponse error = new TokenResponse();
     error.setError( "IOException" );
     error.setErrorDescription( e.getMessage() );
     return error;
  }

我得到以下异常:

 org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z

下面是我的部分pom.xml:

    <!-- JACKSON DEPENDENCY FOR JSON PARSING -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.3</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.9.3</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.3</version>
    </dependency>

    <!-- RETROFIT DEPENDENCY FOR SENDING HTTP REQUESTS -->
    <dependency>
      <groupId>com.squareup.retrofit2</groupId>
      <artifactId>retrofit</artifactId>
      <version>2.3.0</version>
    </dependency>

    <dependency>
      <groupId>com.squareup.retrofit2</groupId>
      <artifactId>converter-jackson</artifactId>
      <version>2.3.0</version>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>logging-interceptor</artifactId>
      <version>3.9.1</version>
    </dependency>

有人可以帮我弄清楚,这有什么问题?

spring maven retrofit2 okhttp3 okio
2个回答
1
投票
BufferedSource 

在okio项目版本1.13.0中。依赖项com.squareup.retrofit2com.squareup.okhttp3都使用此版本。此版本中也包含此方法。版本明智它看起来没问题。

当地环境

现在确保清除maven存储库。也许旧版本在某处挂了。之后执行maven更新项目和全新安装。

Tomcat环境

如果你的tomcat发生这种情况,那么也一定要删除work/Catalina/localhost/文件夹,因为有时可能会在那里缓存一些东西。


0
投票

这可能是因为与依赖项提供的现有Okio版本冲突。

请参阅Spark and Influx: OKIO conflict,与Apache Spark存在冲突。

使用Maven / Gradle dep。树导出以查看所有传递dep,或(在我的情况下):

jar tf /usr/hdp/current/spark-client/lib/spark-assembly-1.6.3.2.6.3.0-235-hadoop2.7.3.2.6.3.0-235.jar | grep okio

这将列出:

okio/BufferedSource.class

然后提取okhttp pom.xml:

jar xf /usr/hdp/current/spark-client/lib/spark-assembly-1.6.3.2.6.3.0-235-hadoop2.7.3.2.6.3.0-235.jar META-INF/maven/com.squareup.okhttp/okhttp/pom.xml
cat META-INF/maven/com.squareup.okhttp/okhttp/pom.xml | grep version

0
投票

经验丰富的类似问题通过YARN在EMR上执行Spark作业,因为应用程序中使用的外部库的Okio / Okhttp依赖项被分布在Spark的系统类路径上的那些重写。

解决方案:在外部库的构建中着色/重定位Okio依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.