尝试运行Spring Cloud Kinesis时出现Spring Cloud ClassNotFoundException

时间:2019-07-19 10:31:03

标签: java spring spring-cloud spring-cloud-stream

最近,我在IntelliJ中使用Spring Initializr打开了一个具有以下依赖项的全新项目。

    <properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-binder-kinesis</artifactId>
      <version>1.2.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-aws</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-aws-messaging</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-test-support</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

并使用非常简单的代码修改了示例类,以仅查看Spring Cloud的工作方式并检查消息。

@SpringBootApplication
@EnableBinding(Processor.class)
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @StreamListener(Processor.INPUT)
    @SendTo(Processor.OUTPUT)
    public String readKinesis(byte[] message) {
        System.out.println(String.format("Reading message... Content -> %s", new String(message)));
        return new String(message);
    }

}

但是,每当我运行项目时,都会显示以下错误。

Caused by: java.lang.ClassNotFoundException: com.google.protobuf.GeneratedMessageV3
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_144]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_144]
... 37 common frames omitted

我也一直在尝试在spring-cloud-stream-samples内执行示例项目,但由于aws-vault凭据(以某种方式似乎与我新创建的项目一起使用),到目前为止,还是没有运气任何其他问题。

还要特别注意,由于找不到绑定器,我手动添加了spring-cloud-stream-binder-kinesis。还要创建一个META-INF目录,并在其中包含一个spring.binders手动指定它。

编辑

发现了问题。

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>

由于某些原因,两个库可能无法在同一个项目中一起使用。应该需要两个不同的版本吗?

0 个答案:

没有答案