How do I set JobParameters in spring batch with spring-boot

spring-batch, spring-boot, spring-el

Solution

I managed to get this working by simply annotating my bean as follows :

@Bean 
@StepScope
public Resource destFile(@Value("#{jobParameters[dest]}") String dest) {
    return new FileSystemResource(dest);
}

Problem

I followed the guide at http://spring.io/guides/gs/batch-processing/ but it describes a job with no configurable parameters. I'm using Maven to build my project. I'm porting an existing job that I have defined in XML and would like to pass-in the jobParameters through the command. I tried the following : ``` @Configuration @EnableBatchProcessing public class MyBatchConfiguration { // other beans ommited @Bean public Resource destFile(@Value("#{jobParameters[dest]}") String dest) { return new FileSystemResource(dest); } } ``` Then I compile my project using : ``` mvn clean package ``` Then I try to launch the program like this : ``` java my-jarfile.jar dest=/tmp/foo ``` And I get an exception saying : ``` [...] Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' ``` Thanks !

Original source