有没有一种方法可以使用Spring Batch 5的默认配置并使用Jackson序列化程序?

huangapple go评论75阅读模式
英文:

Is there a way to use Spring Batch 5 default configuration and use Jackson Serializer?

问题

我正在进行迁移到Spring Batch 5的工作,但在迁移过程中遇到了问题。Spring Batch 5已经更改了默认序列化器。根据这个文档,您需要确保Jackson序列化器位于类路径上,才能使用它。但它并没有详细说明如何启用序列化器的使用。

这份文档指示您可以使用@EnableBatchProcessing注解,另外我还找到了可以扩展DefaultBatchConfiguration类来调整此配置的方法。然而,Spring Boot文档不建议这样做,并指出这将导致Spring Boot回退配置。

当我使用@EnableBatchProcessingDefaultBatchConfiguration时,我们的作业不再像以前那样启动(我使用--spring.batch.job.name参数)。

是否有一种方式可以使用Spring Boot 3提供的默认配置,并在不完全接管Spring Batch的配置的情况下使用Jackson序列化器?问题在于我有使用Jackson序列化器/反序列化器的历史数据,升级后无法再处理这些数据。

英文:

I am working on a migration to Spring Batch 5, but am running into a problem with the migration. Spring Batch 5 has changed the default serializer. According to this doc you need to make sure the Jackson Serializer is on your class path in order to be able to utilize it. It does not specify however how to enable the use of the serializer.

This documentation indicates you can use the @EnableBatchProcessing annotation, and elsewhere I found you can extend the DefaultBatchConfiguration class to adjust this config. However Spring Boot Documentation discourages this and indicates that this will cause Spring Boot to backoff configuration.

When I utilize the @EnableBatchProcessing or DefaultBatchConfiguration our jobs no longer launch as they used to (I utilize the --spring.batch.job.name argument).

Is there a way to use the default configuration that Spring Boot 3 provides and use the Jackson Serializer without needing to completely take over the configuration of Spring Batch? The issue is that I have historical data utilizing the Jackson serializer/deserializer that no longer can be processed by the upgrade.

答案1

得分: 2

Spring Boot 3没有提供一种在不完全控制批处理配置的情况下自定义序列化器的功能(即不使用 @EnableBatchProcessing 或扩展 DefaultBatchConfiguration)。

您可以提出这个功能请求,我会支持。

与此同时,您可以将序列化器定义为应用程序上下文中的一个bean,并通过 @EnableBatchProcessing(executionContextSerializerRef="yourJacksonSerializer") 或扩展 DefaultBatchConfiguration 并重写 getExecutionContextSerializer 来告诉Spring Batch使用它。

我在Spring IO中提到了这个问题,链接在这里

英文:

Spring Boot 3 does not provide a feature to customize the serializer without taking full control on the Batch configuration (ie by using @EnableBatchProcessing or extending DefaultBatchConfiguration).

You can request that feature, I would endorse it.

In the meantime, you can define the serializer as a bean in the application context and tell Spring Batch to use it through @EnableBatchProcessing(executionContextSerializerRef="yourJacksonSerializer") or extend DefaultBatchConfiguration and override getExecutionContextSerializer.

I talked about this at Spring IO here.

huangapple
  • 本文由 发表于 2023年7月11日 01:56:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656204.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定