java-没有阅读器(仅写程序)的简单1步Spring Batch作业可能吗?
作者:互联网
我想知道是否有可能编写一个春季批处理作业,而该步骤只具有一个编写器.我找不到任何有关Spring Batch文档中给定步骤固有必需内容的文档.
我希望做这样的事情:
public class MyBatchConfiguration {
@Bean
public ItemWriter<myInfo> myWriter() {
return new MyWriter();
}
@Bean
public Step myStep(StepBuilderFactory stepBuilderFactory,
ItemWriter<? super Object> myWriter,
PlatformTransactionManager transactionManager) {
return stepBuilderFactory.get("myStep")
.chunk(1)
.writer(myWriter).
transactionManager(transactionManager).
build();
}
@Bean
public Job myBatch(JobBuilderFactory jobs, Step myStep, JobExecutionListener listener) {
return jobs.get("myBatch")
.incrementer(new RunIdIncrementer())
.flow(exceptionReporterStep)
.end()
.listener(listener)
.build();
}
}
解决方法:
一言以蔽之.
似乎您应该使用Tasklet步骤,而不是“分块”步骤.
@Bean
public Step myStep(StepBuilderFactory stepBuilderFactory,
Tasklet myTasklet,
PlatformTransactionManager transactionManager) {
return stepBuilderFactory.get("myStep")
.tasklet(myTasklet)
.transactionManager(transactionManager)
.build();
}
标签:spring-batch,spring,java 来源: https://codeday.me/bug/20191111/2019230.html