使用 ServiceCredentials.fromStream() 方法时出现“java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J”错误。这里有人遇到过这个问题并且知道解决办法吗? TIA
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[title]</groupId>
<artifactId>calendar-event-consumer</artifactId>
<version>0.1</version>
<name>${project.artifactId}</name>
<description>Service that listens for events in a queue to push them
to an external API</description>
<inceptionYear>2017</inceptionYear>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.11.5</scala.version>
<scala.compat.version>2.11</scala.compat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-core_${scala.compat.version}</artifactId>
<version>2.4.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.compat.version}</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-
classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<!--JSON parsing-->
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_2.11</artifactId>
<version>3.5.3</version>
</dependency>
<!--Google Calendar API-->
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev254-1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.20.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<!--Slick -->
<dependency>
<groupId>com.typesafe.slick</groupId>
<artifactId>slick_2.11</artifactId>
<version>3.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -
->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.typesafe.slick</groupId>
<artifactId>slick-hikaricp_2.11</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<args>
<arg>-Xmax-classfile-name</arg>
<arg>128</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-deprecation</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<useFile>false</useFile>
<disableXmlReport>true</disableXmlReport>
<!-- If you have classpath issue like NoDefClassError,... -->
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
<includes>
<include>**/*Test.*</include>
<include>**/*Suite.*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>maven</executable>
<workingDirectory>/tmp</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.qpercom.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
错误日志:
17:40:54.163 [pool-1-thread-3] 信息 c.q.c.rabbitmq.RabbitMQEventConsumer - 收到类型类的消息
com.qpercom.model.CreateOrUpdateEventMessage 事件(185,
omis19demo) 17:40:54.626 [pool-1-thread-3] 信息
com.zaxxer.hikari.HikariDataSource - googleApiDb - 已启动。
17:40:55.553 [pool-1-thread-3] 信息 c.q.c.google.GoogleCalendarPusher
- 在 Google 日历中创建事件 17:40:55.690 [pool-1-thread-3] INFO c.q.c.google.GoogleCalendarPusher - 实例化 Google
日历服务... 17:40:57.063 [pool-1-thread-3] 错误
c.q.c.rabbitmq.RabbitMQEventConsumer - 推送事件失败。这
消息已重新排队。异常痕迹:
java.lang.NoSuchMethodError:
com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J
17:40:57.065 [pool-1-thread-3] 错误
c.r.c.impl.ForgivingExceptionHandler - 消费者
com.qpercom.consumer.rabbitmq.RabbitMQEventConsumer$$anon$1@56acb716
(amq.ctag-CJwhF_0CeOmwK1kBKrQLXw) 通道的方法handleDelivery
AMQChannel(amqp://[电子邮件受保护] /cdn-cgi/l/email-protection:5672/,1) 扔了一个
通道例外
AMQChannel(amqp://[电子邮件受保护] /cdn-cgi/l/email-protection:5672/,1)
java.lang.NoSuchMethodError:
com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J at
com.google.api.client.http.ConsumingInputStream.close(ConsumingInputStream.java:40)
在
com.fasterxml.jackson.core.json.UTF8StreamJsonParser._closeInput(UTF8StreamJsonParser.java:237)
在
com.fasterxml.jackson.core.base.ParserBase.close(ParserBase.java:345)
在
com.fasterxml.jackson.core.json.UTF8StreamJsonParser.close(UTF8StreamJsonParser.java:808)
在
com.google.api.client.json.jackson2.JacksonParser.close(JacksonParser.java:50)
在com.google.api.client.json.JsonParser.parse(JsonParser.java:365)
在com.google.api.client.json.JsonParser.parse(JsonParser.java:337)
在
com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
在
com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
在
com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:444)
在
com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:447)
在
com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:157)
在
com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:145)
在
com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:603)
在
com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:91)
在
com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:88)
在
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:300)
在
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
在
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
在
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
在
com.qpercom.calendar.google.GoogleCalendarPusher.colorIdFor(GoogleCalendarPusher.scala:145)
在
com.qpercom.calendar.google.GoogleCalendarPusher.doCreate(GoogleCalendarPusher.scala:54)
在
com.qpercom.calendar.google.GoogleCalendarPusher.doCreate(GoogleCalendarPusher.scala:25)
在
com.qpercom.calendar.AbstractAPICalendarPusher.pushCreateOrUpdate(AbstractAPICalendarPusher.scala:74)
在 com.qpercom.App$$anonfun$main$1.apply(App.scala:26) 在
com.qpercom.App$$anonfun$main$1.apply(App.scala:22) 在
com.qpercom.consumer.rabbitmq.RabbitMQEventConsumer$$anon$1.handleDelivery(RabbitMQEventConsumer.scala:49)
在
com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
在
com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:100)
在
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
在
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
在 java.lang.Thread.run(Thread.java:748)
With some IDE there's a plugin to debug this kind of case.
Anyway google-api-client 1.22.0
正如你所看到的,取决于guava-jdk5 17
。该版本与google-out-library.oath2-http
需要番石榴版本 > 20
尝试像这样修改你的 pom.xml
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>
产生这个:
这样,您就可以排除旧版本并使用版本 23.0,而不是 17.0。我希望它有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)