Recently, I tried to add a predefined Value with the @Value annotation to a Bean:
@Component
public class TaskletConfig {
@Bean(name = "FilenameExecutionTasklet")
@JobScope
public Tasklet FilenameExecutionTasklet() {
return new Tasklet() {
@Value("#{jobParameters['inputFilename']}")
private String inputFilename;
@Value("${platformImport.jobParameter.inputFile}")
private String inputFile;
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put(inputFile , inputFilename);
return RepeatStatus.FINISHED;
}
};
}
}
which ends up in a NullPointerException. If I do (almost) the same in a Tasklet, it works:
@JobScope
@Component
public class FilenameExecutionTasklet implements Tasklet {
@Value("${platformImport.jobParameter.inputFile}")
private String inputFile;
@Value("#{jobParameters['inputFilename']}")
private String inputFilename;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put(inputFile, inputFilename);
return RepeatStatus.FINISHED;
}
}
Could anybody, please, tell my why? I would have expect both working.
The value of @Value("${platformImport.jobParameter.inputFile}")
is in the application.yml.
NPE is thrown in chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put(inputFile , inputFilename);
with inputFile
.