弹簧批次将不同类别中的步骤分开

您好,如何将不同类中的步骤分开。


 @Configuration

public class JobBatch {

 @Bean

public Job jobCC5(JobBuilderFactory jobBuilders, StepBuilderFactory stepBuilders) throws IOException {

    return jobBuilders.get("jobCC5").start(chStep1(stepBuilders)).build();              }

  }


 @Configuration

public class Step1{

@Bean

public Step Step1(StepBuilderFactory stepBuilders) throws IOException {return stepBuilders.get("step1").<CSCiviqueDTO, String>chunk(100)

    .reader(readerStep1VerifLenghtNir(null)).processor(processorStep1())        .writer(writerStep1(null)).faultTolerant().skipLimit(9).skip(Exception.class).build();

}


烙印99
浏览 89回答 1
1回答

噜噜哒

下面是一个示例。创建一个类,在其中定义步骤:import org.springframework.batch.core.Step;import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;import org.springframework.batch.repeat.RepeatStatus;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class StepConfig {&nbsp; &nbsp; @Autowired&nbsp; &nbsp; private StepBuilderFactory steps;&nbsp; &nbsp; @Bean&nbsp; &nbsp; public Step step() {&nbsp; &nbsp; &nbsp; &nbsp; return steps.get("step")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .tasklet((contribution, chunkContext) -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("hello world");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RepeatStatus.FINISHED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .build();&nbsp; &nbsp; }}然后在作业配置中导入该类:import org.springframework.batch.core.Job;import org.springframework.batch.core.Step;import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Import;@EnableBatchProcessing@Configuration@Import(StepConfig.class)public class JobConfig {&nbsp; &nbsp; @Autowired&nbsp; &nbsp; private JobBuilderFactory jobs;&nbsp; &nbsp; @Bean&nbsp; &nbsp; public Job job(Step step) {&nbsp; &nbsp; &nbsp; &nbsp; return jobs.get("job")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .start(step)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .build();&nbsp; &nbsp; }}希望这有帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java