2

Code snippet:

ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

          JobLauncher jobLauncher = context.getBean("jobLauncher", JobLauncher.class);
          Job job = context.getBean("dadsdeviceJob",Job.class)         

          JobParameters jobParameters =
              new JobParametersBuilder().addString("input.file.name", "cvs/input/fxe_dadsDevice.dat").toJobParameters();

                       try {

                 JobExecution execution = jobLauncher.run(job, jobParameters);

xml snippet:

<bean id="dadsdeviceItemReader"  scope="step" class="org.springframework.batch.item.file.FlatFileItemReader">             
<property name="resource" value="classpath:#{jobParameters['input.file.name']}"/>
              <property name="lineMapper" ref="dadsdeviceLineMapper" />
              <property name="strict" value="false" />
       </bean>
Error: Input resource does not exist class path resource #{jobParameters['input.file.name']}.

can anyone please try to resolve it

Artefacto
  • 96,375
  • 17
  • 202
  • 225
asritha sanka
  • 11
  • 1
  • 3
  • http://stackoverflow.com/questions/13858593/access-job-parameter-in-itemreader-spring-batch-using-grails – hasnae Feb 26 '16 at 17:58

1 Answers1

0

I am not seeing other config details but you can do like this

 JobLauncher jobLauncher = context.getBean("jobLauncher", JobLauncher.class);
     Job job = context.getBean("dadsdeviceJob",Job.class)       
    // get your bean and inject your resources like this before 
      FlatFileItemReader reader = (FlatFileItemReader) context.getBean("dadsdeviceItemReader");
       //       
     reader.setResource(new ClassPathResource(path));
     // or you can give FSR path also like this     
     reader.setResource(new FileSystemResource(path));
Raju Yadav
  • 39
  • 1
  • 6
  • thanks for your suggestion, can you please suggest me, what will be the value need to be mentioned in beans propertyvalue – asritha sanka Feb 28 '16 at 08:05
  • if you are following mentioned above approach then you don't need to set bean resource property in xml config just comment that line. – Raju Yadav Mar 01 '16 at 18:00