gpt4 book ai didi

尝试在 Flink 中创建 Kafka Consumer 时出现 java.lang.NoClassDefFoundError (CheckpointedRestoring)

转载 作者:行者123 更新时间:2023-11-30 06:11:04 26 4
gpt4 key购买 nike

我正在尝试在 Apache Flink 中创建 Kafka Consumer。我一直在遵循 Apache Flink 文档中的设置和指南。但我收到 java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/checkpoint/CheckpointedRestoring 错误。

错误是

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/checkpoint/CheckpointedRestoring
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.agt.examples.KafkaConsumer.main(KafkaConsumer.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.checkpoint.CheckpointedRestoring
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more

KafkaConsumer.class 是

public static void main(String[] args) throws Exception{
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

// For Apache Kafka Consumer
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", "localhost:9092");

DataStream<String> stream = env.addSource(new FlinkKafkaConsumer08<String>("my-flink-topic", new SimpleStringSchema(), properties));

stream.map(new MapFunction<String, String>() {
private static final long serialVersionUID = -6867736771747690202L;

@Override
public String map(String value) throws Exception {
return value;
}
}).print();
env.execute();

pom.xml 是

    <dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.10</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka-0.8_2.10</artifactId>
<version>1.2.1</version>
</dependency>

Flink 版本是 1.4.2,java 版本是 1.8,我使用 intellij IDEA 。我认为这一定与依赖关系未正确链接有关,但我无法理解这里可能存在什么问题。我检查了上面提到的类,但它不在我的库中的流/api/检查点中,当我在线检查时,它似乎是一个已弃用的类。我尝试了 mvn clean install、无效缓存和重新启动、生成源和更新文件夹,但仍然弹出相同的错误。我按照 apache flink 设置页面 https://ci.apache.org/projects/flink/flink-docs-release-1.2/quickstart/java_api_quickstart.html 中的说明创建了该项目但当我从不同来源进行开发时,添加了一些其他依赖项。它与依赖项之一的版本有关吗?我完全超出了我的能力范围。

非常感谢您的帮助:)

最佳答案

您的 flink-clients_2.10flink-connector-kafka-0.8_2.10 依赖项版本似乎不一致。尝试在以下部分中使用 ${flink.version} 而不是 1.2.1:

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.10</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka-0.8_2.10</artifactId>
<version>1.2.1</version>
</dependency>

关于尝试在 Flink 中创建 Kafka Consumer 时出现 java.lang.NoClassDefFoundError (CheckpointedRestoring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50215184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com