迁移到 Spring Boot 2 并使用 Spring Batch 4 [英] Migration to Spring Boot 2 and using Spring Batch 4

查看:31
本文介绍了迁移到 Spring Boot 2 并使用 Spring Batch 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Spring Boot 从 1.4.2 迁移到 2.0.0,其中还包括将 Spring 批处理从 3.0.7 迁移到 4.0.0,当我尝试使用新 Spring 运行它时,批处理似乎不再工作批量版本.

I am migrating Spring Boot from 1.4.2 to 2.0.0, which also includes migrating Spring batch from 3.0.7 to 4.0.0 and it looks like batch process is no longer working when i try to run it with new Spring Batch version.

当我尝试调试时,我发现批处理尝试从 batch_job_execution_context 获取数据时出现问题.

When I tried to debug i found a problem when batch tries to get data from batch_job_execution_context.

我可以看到从数据库中获取数据工作正常,但新版本的批处理无法解析数据库数据

I can see the getting the data from database works fine, but the new version of batch fails to parse database data

{"map":[{"entry":[{"string":["name",""]},{"string":["sender",""]},{"string":["id",""]},{"string":["nav",""]},{"string":["created",140418]}]}]}

{"map":[{"entry":[{"string":["name",""]},{"string":["sender",""]},{"string":["id",""]},{"string":["nav",""]},{"string":["created",140418]}]}]}

出现此错误:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected VALUE_STRING: need JSON String that contains type id (for subtype of java.lang.Object) at [Source: (ByteArrayInputStream); line: 1, column: 9] (through reference chain: java.util.HashMap["map"])

我发现当我删除所有批处理元数据表并从头开始重新创建它们时,批处理似乎又可以工作了.元数据JSON格式好像改成了这个

I have found that when I delete all batch metadata tables and recreate them from scratch, batch seems to work again. It looks like the metadata JSON format has changed to this

{"name":"","sender":"145844","id":"","nav":"","created":"160909"}

{"name":"","sender":"145844","id":"","nav":"","created":"160909"}

我不想删除旧数据以使其再次工作,那么有什么办法可以解决这个问题?

I do not want to delete old data to makes this work again, so is there any way to fix this?

有没有其他人尝试过进行此升级?很高兴知道是否还有其他我可能没有注意到的重大更改.

Has anyone else tried to do this upgrade? It would be nice to know if there are any other breaking changes that I may not have noticed.

谢谢

推荐答案

在 Spring Batch 4 之前,ExecutionContext 的默认序列化机制是通过 XStream.现在它默认使用 Jackson,这与旧的序列化格式兼容.我们仍然可以使用旧版本 (XStreamExecutionContextStringSerializer),但您需要通过实现 BatchConfigurer 并覆盖 JobRepositoryFactoryBean 中的配置来自己配置它>.

Before Spring Batch 4, the default serialization mechanism for the ExecutionContext was via XStream. Now it uses Jackson by default which is not compatible with the old serialization format. We still have the old version available (XStreamExecutionContextStringSerializer) but you'll need to configure it yourself by implementing a BatchConfigurer and overriding the configuration in the JobRepositoryFactoryBean.

为了记录,这与此问题有关:https://jira.spring.io/browse/BATCH-2575.

For the record, this is related to this issue: https://jira.spring.io/browse/BATCH-2575.

这篇关于迁移到 Spring Boot 2 并使用 Spring Batch 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆