【问题标题】:unable to passing parameters through job-parameters using spring batch at runtime无法在运行时使用弹簧批处理通过作业参数传递参数
【发布时间】:2016-02-26 17:22:03
【问题描述】:

代码 sn-p:

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 sn-p:

<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>
错误:输入资源不存在类路径资源#{jobParameters['input.file.name']}。

有人可以尝试解决吗

【问题讨论】:

标签: spring spring-mvc spring-batch


【解决方案1】:

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

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

【讨论】:

  • 感谢您的建议,能否请您建议我,bean 属性值中需要提及的值是多少
  • 如果您遵循上述方法,则无需在 xml 配置中设置 bean 资源属性,只需注释该行即可。
猜你喜欢
  • 2020-04-14
  • 2021-02-11
  • 2021-05-20
  • 2017-11-03
  • 1970-01-01
  • 2015-04-18
  • 2019-11-14
  • 1970-01-01
相关资源
最近更新 更多