How Spring Batch Step Works

I have a requirement when I need to process files based on the rest of the call, in which I get the file name, add it to the job parameter and use it when creating beans.

I create a Beans step scope for (reader, writer) and using the job.I parameter, I start the task in a new thread, because I use the asynchronus task exceutor to start the task, and my question is: Beans are created by spring when we define @StepScope

jobParametersBuilder.addString("fileName", request.getFileName());
jobExecution = jobLauncher.run(job, jobParametersBuilder.toJobParameters());
@Bean
public JobLauncher jobLauncher() {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository());
    jobLauncher.setTaskExecutor(asyncTaskExecutor());
    return jobLauncher;
}

@Bean
@StepScope
public ItemWriter<Object> writer(@Value ("#{jobParameters['fileName']}"String    fileName) {
    JdbcBatchItemWriter<Object> writer = new JdbcBatchItemWriter<>();
    writer.setItemSqlParameterSourceProvider(
        new BeanPropertyItemSqlParameterSourceProvider<Object>());
    writer.setSql(queryCollection.getquery());
    writer.setDataSource(dataSource(fileName));
    return writer;
}
+4
source share
1 answer

A spring StepScope - , , . , , , bean spring . , , spring StepScope, , spring Batch spring .

, StepContext, JobExecutionContext, , .

StepScope , . , , StepScope, , (, StepScope),.

+16

Source: https://habr.com/ru/post/1650251/


All Articles