春季批处理在应用程序启动时停止ItemReader的运行

时间:2018-07-03 05:29:40

标签: spring spring-batch

我正在使用Spring Batch运行从控制器方法触发的作业。一切正常,除非应用程序首次启动8, 10, 0, 10, 10, 80, 2 并运行并读取所有内容。

这是预期的行为吗?没什么大不了的,它只是将启动时间减慢了500秒。

注意:作业本身没有运行,因为我已通过

禁用了该作业
ItemReader

编辑:

配置

  batch:
    job:
      enabled: false

我正在通过{p>发出@Slf4j @Configuration @EnableBatchProcessing public class JobConfiguration { @Value("${app.directoryPath}") public String directoryPath; private final JobBuilderFactory jobBuilderFactory; private final StepBuilderFactory stepBuilderFactory; private final LocationRepository locationRepository; private final VideoRepository videoRepository; public JobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, LocationRepository locationRepository, VideoRepository videoRepository) { this.jobBuilderFactory = jobBuilderFactory; this.stepBuilderFactory = stepBuilderFactory; this.locationRepository = locationRepository; this.videoRepository = videoRepository; } @Bean(name = "importVideo") public Job importVideo(Step processVideos) { return jobBuilderFactory .get("importVideo") .start(processVideos) .build(); } @Bean(name = "processVideos") public Step processVideos(VideoItemReader videoItemReader, VideoProcessor videoProcessor, VideoWriter videoWriter) { return stepBuilderFactory.get("processVideos").<File, Video>chunk(25) .reader(videoItemReader) .processor(videoProcessor) .writer(videoWriter) .build(); } @Bean public VideoWriter videoWriter() { return new VideoWriter(videoRepository); } @Bean public VideoProcessor videoProcessor() { return new VideoProcessor(locationRepository); } @Bean public VideoItemReader videoItemReader() { return new VideoItemReader("file:" + directoryPath, locationRepository); } } 请求来调用该工作

GET

但是我怎么称呼它与它无关,如果我删除该代码,仍然存在相同的行为...

2 个答案:

答案 0 :(得分:0)

这主要是由于spring无法识别spring.batch.job.enabled属性,请尝试将其添加到您的

在Application类中显式加载属性,希望可以解决此问题。

@PropertySource("classpath:batch.properties")

答案 1 :(得分:0)

弄清楚了我的问题,问题在于我的自定义阅读器实现还实现了InitializingBean,它实际上调用了“ getVideos()”。

删除InitializingBean界面会使阅读器在每次引导时都无法运行。