没有生成Spring Batch元表



我在使用Spring Batch的Spring Boot应用程序中遇到此错误。我期待春天批自动生成这些元表。请帮助! !

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

应用程序。属性-我使用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

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

}

使用Spring Boot 3,不需要@EnableBatchProcessing。如果你添加了它,Spring Batch的自动配置(元数据表的创建,在启动时启动作业等)将会退出。

这在Spring Boot 3的迁移指南中提到过。

相关内容

  • 没有找到相关文章

最新更新