未生成Spring批处理元表

thigvfpy  于 2023-01-25  发布在  Spring
关注(0)|答案(1)|浏览(189)

我在使用Spring Batch的Sping Boot 应用程序中遇到了这个错误。我希望Spring Batch自动生成这些 meta表。请帮助!!!

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 - 我现在使用的是H2数据库

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

批处理配置

@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();
    }

}
5n0oy7gb

5n0oy7gb1#

使用 Boot ,不需要@EnableBatchProcessing,如果添加它,SpringBatch的自动配置(元数据表创建、启动时启动作业等)将退出。
Sping Boot 3的迁移指南中提到了这一点。

相关问题