Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring flink中的弹簧自动布线配置_Spring_Spring Boot_Apache Flink_Autowired_Flink Streaming - Fatal编程技术网

Spring flink中的弹簧自动布线配置

Spring flink中的弹簧自动布线配置,spring,spring-boot,apache-flink,autowired,flink-streaming,Spring,Spring Boot,Apache Flink,Autowired,Flink Streaming,我正在尝试使用flink和springboot的组合,我遇到了一些问题。 让我们假设我有这种流动 获取包含一个包含日期字符串的字段日期的json字符串 使用map函数和ObjectMapper将其解析为LocalDateTime对象 印刷品 这是描述我的问题的简单用例 所以,我有一个Word类来表示包含LocalDateTime字段的Word @Data public class Word { @JsonDeserialize(using = LocalDateTimeSerde.cla

我正在尝试使用flink和springboot的组合,我遇到了一些问题。 让我们假设我有这种流动

  • 获取包含一个包含日期字符串的字段日期的json字符串
  • 使用map函数和ObjectMapper将其解析为LocalDateTime对象
  • 印刷品
  • 这是描述我的问题的简单用例

    所以,我有一个Word类来表示包含LocalDateTime字段的Word

    @Data
    public class Word {
        @JsonDeserialize(using = LocalDateTimeSerde.class)
        LocalDateTime date;
    }
    
    LocalDateTimeDeseralization如下所示(我想自动连接应用程序配置):

    DemoApplication.java

    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
    String example = "{\"date\":\"2019-01-29 00:00\"}";
    var stream = env
            .fromElements(example)
            .map(x->new ObjectMapper().readValue(x,Word.class))
            .returns(Word.class);
    stream.print();
    
    env.execute("Demo App");
    
    我得到的例外是:

    Caused by: java.lang.IllegalArgumentException: Class com.example.demo.LocalDateTimeSerde has no default (no arg) constructor
    
    这里的主要问题是反序列化代码在TaskManager上运行,而springboot没有参与其中,因此它没有将AppConf注入类中

    添加@noargsconstuctor不会解决问题

    我想我知道为什么会这样(因为flink master将类序列化给workers,然后springboot不“扫描组件”并控制它)

    有什么解决办法吗?我真的很想把spring和flink结合在worker函数中


    谢谢。

    总的来说,我个人认为混合这些概念不是一个好主意。最简单的解决方案是只在作业管理器上使用
    自动连线
    ,在进入Flink land时使用显式依赖注入

    例如,您可以在DemoApplication中提取日期模式并在ObjectMapper上进行设置。(不要忘记在实际代码中只初始化ObjectMapper一次!)

    如果你真的想使用自动连线。我想你需要在taskmanager上手动触发自动连线。有一个

    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
    String example = "{\"date\":\"2019-01-29 00:00\"}";
    var stream = env
            .fromElements(example)
            .map(x->new ObjectMapper().readValue(x,Word.class))
            .returns(Word.class);
    stream.print();
    
    env.execute("Demo App");
    
    Caused by: java.lang.IllegalArgumentException: Class com.example.demo.LocalDateTimeSerde has no default (no arg) constructor