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
@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; }
A spring StepScope - , , . , , , bean spring . , , spring StepScope, , spring Batch spring .
StepScope
, StepContext, JobExecutionContext, , .
StepContext
JobExecutionContext
StepScope , . , , StepScope, , (, StepScope),.
Source: https://habr.com/ru/post/1650251/More articles:Create autoload function from macro - macrosAvoiding mutable booleans indicating state - f #Setting up Postman to test the API when using passport authorization - restOpenSSL.crypto.X509.sign () throws object '' bytes does not have the attribute 'encode' "- pythonError calling parent class constructor? - constructorMy AJAX request is not validated correctly - jquerygpg failed to sign data. Failed to write commit object - gitHow does 32-bit architecture differ from 64-bit architecture mainly in the form of application speed and memory management? - iosSpark Streaming Job Saves Growing Memory - memory-leaksbash operation to count array elements inaccessible - linuxAll Articles