spring-boot - 迁移到 Spring Boot 2 并使用 Spring Batch 4

标签 spring-boot spring-batch

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

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

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

{"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 格式已更改为此

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



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

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

谢谢

最佳答案

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

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

关于spring-boot - 迁移到 Spring Boot 2 并使用 Spring Batch 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49625231/

相关文章:

spring-boot - 如何在 Cloud Foundry 使用 Spring Boot 外部化配置

java - Spring 批处理中的并行项目编写器

Spring Batch Step 不执行

java - 使用 itemReader Spring Batch 读取 XML 中节点的属性

java - Spring批处理聚合值并写入单个值

java - 在 Spring Boot 应用程序中关闭浏览器选项卡时结束 JVM

java - 由 : org. springframework.data.mapping.PropertyReferenceException: No property findAll found for type User - Redis 引起

spring boot rest tomcat部署报错

java - 创建多模块maven项目时出错

java - Spring Batch 重复调用某个项目的处理器