我已经阅读了这个论坛,其中有很多关于如何使用作业参数的例子,但是当我在检索作业参数时获得空值时仍然卡住了
以下是我目前的代码
控制器:
@RestController
@CrossOrigin
@RequestMapping("/bulkimport/api/")
public class BatchController {
@Autowired
public JobLauncher jobLauncher;
@Autowired
public Job bulkImportJob;
@RequestMapping(value = "/bulkProcessjob", method = RequestMethod.POST)
public void batchImportProcess(@RequestHeader(value = "X-Auth-Token") String jwtToken,
@RequestParam("excelfile") final MultipartFile excelfile
) throws IOException{
String path = new ClassPathResource("importFileFolder/").getURL().getPath();
File fileToImport = new File(path + excelfile.getOriginalFilename());
try {
Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
jobParametersMap.put("processName", new JobParameter("processName"));
jobParametersMap.put("operation", new JobParameter("operation"));
jobParametersMap.put("filePath", new JobParameter(fileToImport.getAbsolutePath()));
System.out.println(fileToImport.getAbsolutePath()+"filePath:::::::::::");
jobLauncher.run(bulkImportJob, new JobParameters(jobParametersMap));
}catch(Exception e){
}
}
}
配置类:
public String filePath;
@Bean(name = "bulkImportJob")
public Job bulkImportJob() {
return jobBuilderFactory.get("bulkImportJob").incrementer(new RunIdIncrementer()).flow(bulkImportProcessStep()).end().build();
}
@Bean
public Step bulkImportProcessStep() {
return stepBuilderFactory.get("bulkImportProcessStep").<String, String> chunk(1).reader(validateFileHeader(filePath)).writer(new TempWriter()).build();
}
@Bean
@StepScope
BulkUploadExcelHeader validateFileHeader(@Value("#{jobParameters[filePath]}") String filePath) {
System.out.println("filePath value::::::::::::::::::::::::::::::::"+filePath);
return new BulkUploadExcelHeader(filePath);
}
在上面的print语句中,filePath值打印为null
任何人都可以在上面的代码中提出错误建议
答案 0 :(得分:0)
最有可能你需要用单引号括起filePath:
validateFileHeader(@Value("#{jobParameters['filePath']}")