Home > Enterprise >  Spring Batch metatables are not generated
Spring Batch metatables are not generated

Time:01-21

I am experiencing this error in my Spring Boot app using Spring Batch. I am expecting Spring Batch to autogenerate those meta tables. Please help!!!

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "BATCH_JOB_INSTANCE" not found (this database is empty); SQL statement:
SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ? [42104-214]

pom.xml

Spring Boot: 3.0.1
Spring Batch starter: 3.0.1
Spring Batch Core: 5.0.0

application.properties - I am using H2 database for the meantime

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true

BatchConfig

@Configuration
@EnableBatchProcessing
public class BatchConfig {


    @Bean
    public Job uploadSupplierJob(JobRepository jobRepository, Step step1) {
        return new JobBuilder("uploadSupplierJob", jobRepository)
                .start(step1)
                .build();
    }


    @Bean
    public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, FlatFileItemReader<SupplierCsv> supplierItemReader, ItemWriter supplierItemWriter) {
        return new StepBuilder("step1", jobRepository)
                .chunk(10, transactionManager)
                .reader(supplierItemReader)
                .writer(supplierItemWriter)
                .build();
    }


    @Bean
    @StepScope
    public FlatFileItemReader<SupplierCsv> supplierItemReader(@Value("#{jobParameters['file']}") MultipartFile file) throws IOException {
        return new FlatFileItemReaderBuilder<SupplierCsv>().name("supplierItemReader")
                .resource(new InputStreamResource(file.getInputStream()))
                .delimited()
                .names("name", "contactName", "terms","notes","leadDays","address","phoneNumber")
                .fieldSetMapper(new BeanWrapperFieldSetMapper<SupplierCsv>() {{
                    setTargetType(SupplierCsv.class);
                }})
                .build();
    }


}

CodePudding user response:

With Spring Boot 3, there is no need for @EnableBatchProcessing. If you add it, the auto-configuration of Spring Batch (meta-data tables creation, launching of jobs at startup, etc) will back off.

This is mentioned in the migration guide of Spring Boot 3.

  • Related