spring-projects/spring-batch

Deprecate jobRepository method in JobBuilderHelper & StepBuilderHelper

acktsap opened this issue · 1 comments

As of 5.0.0, it's recommanded to use JobBuilder, StepBuilder with JobRepository like this.

@Bean
public Job testJob(JobRepository jobRepository) {
    return new JobBuilder("testJob", jobRepository)
        .start(
            new StepBuilder("testStep", jobRepository)
                .tasklet((a, b) -> RepeatStatus.FINISHED, new ResourcelessTransactionManager())
                .build()
        )
        .build();
}

But i still can set JobRepository when building Job or Step like this.

@Bean
public Job testJob(JobRepository jobRepository) {
    return new JobBuilder("testJob", jobRepository)
        .start(
            new StepBuilder("testStep", jobRepository)
                .tasklet((a, b) -> RepeatStatus.FINISHED, new ResourcelessTransactionManager())
                .repository(jobRepository) // this
                .build()
        )
        .repository(jobRepository) // this
        .build();
}

It looks redundant since it's already set in constructor. So, how about remove repository method in JobBuilderHelper and StepBuilderHelper? Maybe it's better to deprecate first and remove in 6.0.0

/**
* Sets the job repository for the job.
* @param jobRepository the job repository (mandatory)
* @return this to enable fluent chaining
*/
public B repository(JobRepository jobRepository) {
properties.jobRepository = jobRepository;
@SuppressWarnings("unchecked")
B result = (B) this;
return result;
}

public B repository(JobRepository jobRepository) {
properties.jobRepository = jobRepository;
return self();
}

Thank you for reporting this. It makes sense, and indeed, it could be confusing. I will plan the deprecation for v5.1.