Since Spring Batch 5, it's possible to easily specify a custom ExecutionContextSerializer by @EnableBatchProcessing as shown below:
@Configuration
@EnableBatchProcessing(executionContextSerializerRef = "myCustomSerializer")
public class MyJobConfigWithCustomSerializer {
@Bean
public ExecutionContextSerializer myCustomSerializer() {
Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
// customize serializer
return serializer;
}
}
(The example is from https://spring.io/blog/2022/11/24/spring-batch-5-0-goes-ga )
However, when using BatchAutoConfiguration in Spring Boot, there isn’t a straightforward way to achieve this.
This pull request modifies the BatchAutoConfiguration to refer to an ExecutionContextSerializer registered in the ApplicationContext.
The behavior of the ExecutionContextSerializer has changed in Spring Batch 5.0. ( https://github.com/spring-projects/spring-batch/issues/4122 ) So, if this feature is available, I expect it to be more helpful for those who prefer the behavior of old versions to upgrade to the latest version.
I believe the changes in this PR represent a user-expected behavior. In Spring Batch, DefaultJobParametersConverter is used as a similar policy. The class is used by default, but if there is another implementation class that the user has registered in ApplicationContext, it is replaced. And this is also a natural convention in Spring Boot.
Comment From: philwebb
@fmbenhassine any chance of a quick review? The changes looks sensible to me.
Comment From: cachescrubber
Hi @benelog, I already provided a PR to support a custom ExecutionContextSerializer few weeks ago: Please see #38328
Comment From: philwebb
Thanks @cachescrubber, I'm a bit behind with issues and I didn't notice. I also see @fmbenhassine has already reviewed that one.
Sorry @benelog, but I'm going to have to close this one as a duplicate of #38328
Comment From: benelog
@philwebb I'm sorry to bother you as I haven't searched for other PRs. I'm satisfied because it's expected to be included in Spring Boot 3.3.
Thank you for your care.