-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Milestone
Description
AbstractStep
requires a job repository, yet allows constructing new instances without providing one. This fails at runtime with v5.2.2:
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.StepExecution;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableBatchProcessing
public class HelloWorldJobConfiguration {
@Bean
public Step step() {
return new AbstractStep() {
@Override
protected void doExecute(StepExecution stepExecution) throws Exception {
System.out.println("Hello, World!");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
}
};
}
@Bean
public Job job(JobRepository jobRepository, Step step) {
return new JobBuilder("job", jobRepository).start(step).build();
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldJobConfiguration.class);
JobOperator jobOperator = context.getBean(JobOperator.class);
Job job = context.getBean(Job.class);
jobOperator.start(job, new JobParameters()); // fails with "JobRepository must not be null"
}
}
It should not be possible to create an AbstractStep
without providing a job repository at compile time.
HyunSangHan