Announcement Announcement Module
No announcement yet.
Forward value from Job to Step Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forward value from Job to Step


    I'm starting in "Spring Batch" for a new project, so first, I'd like to apologize if my question could seem a bit stupid...

    I'd like to parse a flat file using the "FlatFileItemReader" in a step. This, I find how to do it.
    But, I'd like to provide the name of file to parse into the Job parameters (an not in the property in the xml conf file.
    How can I forward this parameter, from my Job, as a ressource to my Step ?

    Thanks to help me please...or at least, if somebody has a good tutorial about Spring Batch basics.

  • #2
    Finally, I think I almost find a solution.

    I tried this:
    <bean id="itemReader" class="MyItemReader">
    <property name="resource" value="file:${path}/#{jobParameters[]}" />

    and in my reader I put this:
    public class MyItemReader implements ItemReader {

    private Resource resource;

    public Resource getResource() {
    return resource;

    public void setResource(Resource resource) {
    this.resource= resource;

    public Person read() throws Exception, UnexpectedInputException, ParseException {

    System.out.println("Ressource exist: " + resource.exists());

    return null;

    As you can see, I put as less code as possible. As I want to understand where exactly the problem comes from.
    The result i have in the console is:
    "Ressource exist: false"

    I don't manage to get the filename, why ? However, I can see it's good in the log for JobParameter.


    • #3
      Which version of Spring Batch are you using? The late-binding syntax ("#{jobParameters[]}") only works in 2.0.


      • #4
        Yes I have 2.0 version.
        Could the problem come from the fact I don't extend/use the FlatFileItemReader ?


        • #5
          You need to declare that the reader has "step scope".

          <bean id="itemReader" class="MyItemReader" scope="step">
              <property name="resource" value="file:${path}/#{jobParameters[]}" />
          If you're not using the batch namespace, you'll also need to declare the StepScope bean:

          <bean class="org.springframework.batch.core.scope.StepScope" />


          • #6
            Yes, it's working now.
            Thanks a lot for your help