Skip to content

Support user-defined ExecutionContextSerializer in BatchAutoConfiguation #38631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

benelog
Copy link
Contributor

@benelog benelog commented Dec 1, 2023

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. ( spring-projects/spring-batch#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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 1, 2023
@benelog benelog force-pushed the register-ec-context-ser branch from 8489ac5 to e36c8da Compare December 1, 2023 21:09
@benelog benelog force-pushed the register-ec-context-ser branch from e36c8da to 87ebf2a Compare December 3, 2023 08:10
@philwebb
Copy link
Member

philwebb commented Dec 4, 2023

@fmbenhassine any chance of a quick review? The changes looks sensible to me.

@philwebb philwebb added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Dec 4, 2023
@cachescrubber
Copy link
Contributor

Hi @benelog, I already provided a PR to support a custom ExecutionContextSerializer few weeks ago: Please see #38328

@philwebb
Copy link
Member

philwebb commented Dec 5, 2023

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

@philwebb philwebb closed this Dec 5, 2023
@philwebb philwebb added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels Dec 5, 2023
@benelog
Copy link
Contributor Author

benelog commented Dec 5, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants