简体   繁体   中英

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.platformThreadFactory()Ljava/util/concurrent/ThreadFactory;

Actually I am trying to get the topic in cloud pub/sub. I have written the code with restful web services when I send the request URL to get the topic i am getting above error. After some lookup,it seams like versions conflict of pub/sub 0.17 version and guava 19.o version but I excluded guava 19 version and added 18 version but same exception coming again and again. However I tried with all guava version but no use same error is coming. Please guide me how to solve and why it is coming. I am going to attach my code here.. Thanks..

My code:

 @Path("/topic")
  public class PubSubServices 
  {

    @Path("/gettopic")
    @GET
    @Produces({ MediaType.TEXT_HTML})
    public Response getTopic() throws Exception {
        String  projectid="My-ProjectID";
        String topicname="my-new-topic";


        System.out.println("Project name is:"+projectid+"  new topic name is:"+topicname);
        try 
        {

        TopicAdminClient topicAdminClient   topicAdminClient=TopicAdminClient.create();
             TopicName topicName = TopicName.create(projectid, topicname);
              Topic topic = topicAdminClient.getTopic(topicName);

        } catch(Exception e)
        {
            e.printStackTrace();
        }

        return Response.status(200).entity(topic.getName();).build();


    }

Pom.xml:

    <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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PubSub</groupId>
<artifactId>PubSub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>

    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-pubsub</artifactId>
        <version>0.17.2-alpha</version>
        <exclusions>
            <exclusion>
                <artifactId>com.google</artifactId>
                <groupId>guava</groupId>
            </exclusion>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>


    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId> 
        <version>18.0</version> 
   </dependency> 

    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.22.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>com.thetransactioncompany</groupId>
        <artifactId>cors-filter</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

</dependencies>
<build>
    <finalName>CloudSubPub1</finalName>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

i created war file and i uploaded in glass fish server. when i send request error coming.. seams like the Guava-18 is being overwrite by an older version at runtime, and Guava-18 only works during compile task.

With Main Method It is working gud(Test with main method)

Code:

package com.agro.pubsub.services;
import com.google.cloud.pubsub.spi.v1.TopicAdminClient;
import com.google.pubsub.v1.Topic;
import com.google.pubsub.v1.TopicName;

public class Test {
public static void main(String args[]) throws Exception
{

     try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
          TopicName topicName = TopicName.create("My-project-Id", "my-new-topic123");
          Topic topic = topicAdminClient.getTopic(topicName);
    System.out.println(""+topic.getName());
     }

}
}

Pom.xml :

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PubSub</groupId>
<artifactId>PubSub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>


  <dependencies>

          <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>google-cloud-pubsub</artifactId>
                <version>0.17.2-alpha</version>
         </dependencies>
  </project>

Problem is that when I write code with restful web services with jersey I am getting above error, I am not able find solution. Any solution for this please?

I got solution to it. I copied guava 19 version into glass fish modules folder so it means i am overriding guava with my guava version

SOLVED: I updated the Guava dependency to latest version and it solved the issue

 <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>latest</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.platformThreadFactory() while running fabric-sdk-java in Weblogic 12c Need help on NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; in IntelliJ NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet(Ljava/util/Comparator;)Ljava/util/stream/Collector; Spark : java.lang.NoSuchMethodError: com.google.common.collect.Ordering.leastOf(Ljava/util/Iterator;I)Ljava/util/List java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create at org.openqa.selenium.remote.service.DriverService.wa NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor conflits on Elastic Search jar java.lang.IllegalAccessError: tried to access method com.google.common.util.concurrent.SimpleTimeLimiter.(Ljava/util/concurrent/ExecutorService;)V [on hold] Spring Boot + ReactiveCosmosRepository + java.lang.NoSuchMethodError: reactor.util.concurrent.Queues.empty()Ljava/util/function/Supplier Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM