原因:因为Flink 加载 table Factory 使用的时SPI机制,而正常的flink jar包是不包含META-INF.services 路径的,需要自己去添加
org.apache.flink.table.factories.TableFactory
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactory
org.apache.flink.connector.jdbc.catalog.factory.JdbcCatalogFactory
org.apache.flink.connector.jdbc.table.JdbcTableSourceSinkFactory
org.apache.flink.streaming.connectors.redis.RedisTableSinkFactory
org.apache.flink.connectors.kudu.table.KuduTableFactory
org.apache.flink.connectors.kudu.table.KuduCatalogFactory
参考链接:https://blog.csdn.net/u013516966/article/details/106536525
方法二 maven 添加插件(推荐)
<build> <plugins> <!-- Java Compiler --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>${target.java.version}</source> <target>${target.java.version}</target> </configuration> </plugin> <!-- We use the maven-shade plugin to create a fat jar that contains all necessary dependencies. --> <!-- Change the value of <mainClass>...</mainClass> if your program entry point changes. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.1</version> <executions> <!-- Run shade goal on package phase --> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <!--<transformers combine.children="append"> <!– The service transformer is needed to merge META-INF/services files –> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> <!– ... –> </transformers>--> <!-- 合并多个connetor 的META-INF.services 文件--> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>reference.conf</resource> </transformer> <!-- The service transformer is needed to merge META-INF/services files --> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"> <projectName>Apache Flink</projectName> <encoding>UTF-8</encoding> </transformer> </transformers> <!-- 自动排除不使用的类,缩小jar包体积--> <!-- <minimizeJar>true</minimizeJar>--> <artifactSet> <excludes> <exclude>org.apache.flink:force-shading</exclude> <exclude>org.slf4j:*</exclude> <exclude>org.apache.logging.log4j:*</exclude> </excludes> <!--<includes> <indlude>com.aliyun.openservices:flink-log-connector</indlude> <indlude>com.alibaba.hologres:hologres-connector-flink-1.12</indlude> <indlude>com.google.guava:guava</indlude> <indlude>org.projectlombok:lombok</indlude> </includes>--> </artifactSet> <filters> <filter> <!-- Do not copy the signatures in the META-INF folder. Otherwise, this might cause SecurityExceptions when using the JAR. --> <artifact>*:*</artifact> <excludes> <exclude>module-info.class</exclude> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build>