jobBuilderFactory deprecation

29 views Asked by At

I'm using the following factories to set up my Spring Batch application: private JobBuilderFactory jobBuilderFactory; private StepBuilderFactory stepBuilderFactory;

And I am getting the following error message: The type JobBuilderFactory has been deprecated since version 5.0.0 and marked for removal as well as Cannot resolve symbol StepBuilderFactory

These are the beans I am declaring : ` public class BatchConfiguration {

private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;

public BatchConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
    this.jobBuilderFactory = jobBuilderFactory;
    this.stepBuilderFactory = stepBuilderFactory;
}

@Bean
public FlatFileItemReader<Person> reader() {
    return new FlatFileItemReaderBuilder<Person>()
            .name("personItemReader")
            .resource(new ClassPathResource("sample-data.csv"))
            .delimited()
            .names("prhoin", "nrhoin")                  .targetType(Person.class)
            .build();
}

@Bean
public PersonItemProcessor processor() {
    return new PersonItemProcessor();
}

@Bean
public JdbcBatchItemWriter<Person> writer(DataSource dataSource) {
    return new JdbcBatchItemWriterBuilder<Person>()
            .sql("INSERT INTO people (PRHOIN, NRHOIN) VALUES (:prhoin, :nrhoin)")
            .dataSource(dataSource)
            .beanMapped()
            .build();
}

@Bean
public Step step1(JobRepository jobRepository, DataSourceTransactionManager transactionManager,
                  FlatFileItemReader<Person> reader, PersonItemProcessor processor, JdbcBatchItemWriter<Person> writer) {
    return new StepBuilder("step1")
            .jobRepository(jobRepository)
            .<Person, Person> chunk(3)
            .reader(reader)
            .processor(processor)
            .writer(writer)
            .transactionManager(transactionManager)
            .build();
}

@Bean
public Job importUserJob(JobBuilderFactory jobBuilderFactory, Step step1) {
    return jobBuilderFactory.get("importUserJob")
            .incrementer(new RunIdIncrementer()) // Set the incrementer
            .start(step1)
            .build();
}

} ` Thank you for your help, I am stuck.

I have been trying to replace this deprecated builder without success for a few days.

0

There are 0 answers