大java.lang.ClassNotFoundException:org.apache.flink.connector.kafka.source.KafkaSource

Flink java.lang.ClassNotFoundException: org.apache.flink.connector.kafka.source.KafkaSource

我使用 Kafka 作为 Flink 作业的数据源。当我将作业部署到 flink 集群作业管理器时,我收到错误 ClassNotFoundException: Caused by: java.lang.ClassNotFoundException: org.apache.flink.connector.kafka.source.KafkaSource

以下是我的 pom.xml 家属

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-connector-kafka_2.12</artifactId>
            <version>1.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-avro</artifactId>
            <version>1.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_2.12</artifactId>
            <version>1.13.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
    </dependencies>

Flink本身不包含这些扩展JAR文件(你可以在flink/lib中找到jar文件),如果你不将这些jar文件放入你的项目的JAR文件(uber jar)中,或者在提交时指定它们任务(参见 Flink 文档),flink 运行时将找不到这些 Jars。

Flink connector默认不在flink classpath下,需要在项目中添加kafka connector maven依赖