【发布时间】:2019-09-23 16:31:34
【问题描述】:
上传后传一个动态文件名到spring batch进行处理
我是 Spring Batch 的新手,我想要完成的是从一个应用程序上传一个 csv 文件,然后使用上传文件的文件名向 Spring Batch 发送一个发布请求,并让 Spring Batch 从定位它并处理它。
我尝试将字符串值传递给阅读器,但我不知道如何在步骤中访问它
// controller where i want to pass the file name to the reader
@RestController
public class ProcessController {
@Autowired
JobLauncher jobLauncher;
@Autowired
Job importUserJob;
@PostMapping("/load")
public BatchStatus Load(@RequestParam("filePath") String filePath) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
JobExecution jobExecution = jobLauncher.run(importUserJob, new JobParametersBuilder()
.addString("fullPathFileName", filePath)
.toJobParameters());
return jobExecution.getStatus();
}
}
//reader in my configuration class
@Bean
public FlatFileItemReader<Person> reader(@Value("#{jobParameters[fullPathFileName]}") String pathToFile)
// the problem is here at the .reader chain
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader(reader))
.processor(processor())
.writer(writer())
.build();
}
我希望将文件名传递给阅读器 amd spring batch 可以处理它
【问题讨论】:
-
请分享csv文件和人物类
标签: java spring spring-batch