【发布时间】:2018-11-12 13:31:59
【问题描述】:
我正在尝试创建一个 tasklet 并写入 couchbase。
@Configuration
@EnableBatchProcessing
public class BatchConfiguration extends
DefaultBatchConfigurer {
@Autowired
private JobBuilderFactory jobBuilders;
@Autowired
private StepBuilderFactory stepBuilders;
@Bean
public Step updatedatabaseStep(){
return stepBuilders.get("updatedatabaseStep").tasklet(new UpdateLocalDbStep()).build();}
我的步骤
public class UpdateLocalDbStep implements Tasklet, StepExecutionListener {
@Autowired
private CouchBaseRepository
couchBaseRepository;
@Override
public RepeatStatus execute(StepContribution arg0, ChunkContext chunkContext) throws Exception {
couchBaseRepository.save(this.table);
return RepeatStatus.FINISHED;
}
我的 Couchbase 服务
@Repository
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "ownerDetails")
public class CouchBaseRepository {}
每次我在执行声明 CouchBaseRepository 为空的步骤时收到空指针异常
2018-11-12 18:59:10.435 INFO 56531 --- [
main] c.p.r.s.impl.steps.UpdateLocalDbStep
: Updating local db with lated table
info_incr
2018-11-12 18:59:10.440 ERROR 56531 --- [
main] o.s.batch.core.step.AbstractStep
: Encountered an error executing step
updatedatabaseStep in job findOwnerJob
java.lang.NullPointerException: null
at
com.restbatchApi.service.impl.steps.UpdateLocalDbStep.execute(UpdateLocalDbStep.java:58) ~[classes/:na] 在 org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.1.0.RELEASE.jar:4.1.0.RELEASE] 在 org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.1.0.RELEASE.jar:4.1.0.RELEASE] 在 org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
【问题讨论】:
-
我们必须做一些批处理,而我刚刚开始了解 spring-batch。我们还有一个 couchbase 数据库。据我了解,spring-batch 并没有开箱即用地支持沙发底座。您在使用 spring batch + couchbase 时遇到了哪些挑战。还有你是如何处理jobrepository bean的,尤其是事务管理器(因为它们在couchbase中没有事务的概念)。
标签: spring spring-boot spring-batch couchbase