fra*_*iCe 3 java spring spring-batch spring-boot
我在使用 Spring Batch 的 Spring Boot 应用程序中遇到此错误。我期待 Spring Batch 自动生成这些元表。请帮忙!!!
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]
Run Code Online (Sandbox Code Playgroud)
pom.xml
Spring Boot: 3.0.1
Spring Batch starter: 3.0.1
Spring Batch Core: 5.0.0
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
批量配置
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
使用 Spring Boot 3,不需要@EnableBatchProcessing. 如果添加它,Spring Batch 的自动配置(元数据表创建、启动时启动作业等)将会停止。
Spring Boot 3的迁移指南中提到了这一点。
| 归档时间: |
|
| 查看次数: |
898 次 |
| 最近记录: |