Apache Flink table-walkthrough执行mvn install时缺失依赖报错
mvn install时的ExecutorFactory缺失报错 报错详情
org.apache.flink.table.api.ValidationException: Could not find any factories that implement 'org.apache.flink.table.delegation.ExecutorFactory' in the classpath.
at org.apache.flink.table.factories.FactoryUtil.discoverFactory(FactoryUtil.java:387)
at org.apache.flink.table.api.internal.TableEnvironmentImpl.create(TableEnvironmentImpl.java:295)
at org.apache.flink.table.api.internal.TableEnvironmentImpl.create(TableEnvironmentImpl.java:266)
at org.apache.flink.table.api.TableEnvironment.create(TableEnvironment.java:95)
at org.apache.flink.playgrounds.spendreport.SpendReportTest.testReport(SpendReportTest.java:52)
问题原因
该报错是因为测试代码初始化TableEnvironment时,类路径中缺少提供ExecutorFactory实现的依赖包。Flink Table API需要依赖planner组件来提供执行器工厂,本地测试场景下必须显式引入对应依赖。
解决方案
- 添加planner依赖:在项目的
pom.xml中添加对应版本的Flink Table Planner依赖,针对你使用的Flink 1.15版本,推荐添加:
<dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-table-planner-loader</artifactId> <version>1.15.0</version> <scope>test</scope> </dependency>
如果是基于Scala的项目,也可以使用带Scala版本后缀的planner依赖:
<dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-table-planner-blink_2.12</artifactId> <version>1.15.0</version> <scope>test</scope> </dependency>
- 核对版本一致性:确保pom.xml中所有Flink相关依赖的版本与官方文档使用的1.15版本完全一致,避免版本不匹配导致的依赖兼容问题。
- 清理重建项目:执行
mvn clean install命令,清理之前的构建缓存后重新构建,确保新依赖被正确加载。
内容的提问来源于stack exchange,提问作者Mihaita Tinta

