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

时间:2017-05-15 05:49:50

标签: java rest maven jersey google-cloud-pubsub

其实我正在尝试在cloud pub / sub中获取主题。当我发送请求URL以获取上述错误的主题时,我已经用宁静的Web服务编写了代码。经过一些查询后,它会像pub / sub 0.17版本和番石榴19.o版本的版本冲突一样,但我排除了guava 19版本并添加了18个版本,但同样的异常会一次又一次地出现。但是我尝试了所有番石榴版本,但没有使用相同的错误即将到来。请指导我如何解决以及它为什么会来。 我要在这里附上我的代码.. 感谢..

我的代码:

 @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>

我创建了war文件,我上传到玻璃鱼服务器。当我发送请求错误时...像Guava-18这样的接口在运行时被旧版本覆盖,而Guava-18仅在编译任务期间工作。

使用主要方法工作gud(使用main方法测试)

代码:

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>
  

问题是,当我使用带有jersey的restful web服务编写代码时,我遇到了上述错误,我无法找到解决方案。        有什么解决方案吗?

2 个答案:

答案 0 :(得分:0)

我得到了解决方案。我将番石榴19版复制到玻璃鱼模块文件夹中 所以这意味着我用我的番石榴版本重写番石榴

答案 1 :(得分:0)

解决:我将Guava依赖关系更新为最新版本,它解决了问题

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