1.问题描述
在idea中运行flink job程序出现如下错误:
Exception in thread "main" java.lang.IllegalStateException: No ExecutorFactory found to execute the application.
at org.apache.flink.core.execution.DefaultExecutorServiceLoader.getExecutorFactory(DefaultExecutorServiceLoader.java:88)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.executeAsync(StreamExecutionEnvironment.java:2085)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1983)
at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:68)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1969)
at test.ReadTextDemo.main(ReadTextDemo.java:19)
2.问题分析
程序代码如下;
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.12</version>
</dependency>
</dependencies>
package test;
import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
* @Description
* @Author XXX
* @Date 2024/5/23
* @Version 1.0
*/
public class ReadTextDemo {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
TextInputFormat textInputFormat = new TextInputFormat(null);
DataStreamSource<String> source = env.readFile(textInputFormat, "D:\\datatest\\readtext.txt");
source.print();
env.execute("readText test");
}
}
代码比较简单,应该没问题,因此不用分析。
从报错信息可以看出,程序没有找到执行器工厂(ExecutorFactory)来执行应用程序中的任务,网上查询了下,出现该报错的原因有以下几个:
参考:no executorfactory found to execute the application_慕课手记
因为改flink 程序没有什么配置,因此可以排除1、3,那最有可能得原因就是2,缺少pom依赖,通过在flink官网可知:
所以应该是缺少flink-clients依赖,加上pom依赖,问题得到解决:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients</artifactId>
<version>${flink.version}</version>
</dependency>