2016-02-26 110 views
2

代码通过使用Spring Batch的通过工作参数参数片段:无法在运行时

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片段:

<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']}. 

谁能请尽力解决

+0

http://stackoverflow.com/questions/13858593/access-job-parameter-in-itemreader-spring-batch-using-grails – hasnae

回答

0

我没有看到其他配置细节,但你可以像这样

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)); 
+0

感谢您的建议,能否请您提出建议,如果您是以下提及的上述方法,那么您需要在bean properties valueue –

+0

中提到什么值,那么您不需要在xml config中设置bean资源属性,只需注释该行即可。 <! - - > –