Spring 弹簧批+;弹簧靴&x2B;卧铺

Spring 弹簧批+;弹簧靴&x2B;卧铺,spring,spring-boot,spring-batch,couchbase,Spring,Spring Boot,Spring Batch,Couchbase,我正在尝试创建一个tasklet并写入couchbase @Configuration @EnableBatchProcessing public class BatchConfiguration extends DefaultBatchConfigurer { @Autowired private JobBuilderFactory jobBuilders; @Autowired private StepBuilderFactory stepBuilders; @Bean pu

我正在尝试创建一个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;
}
我的卧铺服务

@Repository
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "ownerDetails")
public class CouchBaseRepository {}
每次我在执行声明CouchBaseRepository为null的步骤时收到null指针异常

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]

中,您正在使用
新建UpdateLocalDbStep()
创建tasklet,因此此实例不受spring容器管理,因此不会注入此对象的依赖项

您需要将tasklet声明为bean:

@Bean
public Tasklet tasklet() {
   return new UpdateLocalDbStep();
}
并在步骤定义中引用:

@Bean
public Step updatedatabaseStep(){
   return stepBuilders.get("updatedatabaseStep").tasklet(tasklet()).build();
}

作为补充说明,我建议为您的tasklet注入构造函数(使用
CouchBaseRepository
作为参数创建构造函数)。

谢谢@Mahmoud Ben Hassine我们必须进行一些批处理,我刚刚开始了解spring批处理。我们还有一个couchbase数据库。据我所知,SpringBatch不支持开箱即用的couchbase。使用SpringBatch+couchbase时,您遇到了什么挑战。另外,您如何处理jobrepository bean,尤其是事务管理器(因为它们在couchbase中不是事务的概念)。