2016-02-26 111 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資源屬性,只需註釋該行即可。 <! - - > –