如何使用 spring-boot 在 spring 批处理中设置 JobParameters [英] How do I set JobParameters in spring batch with spring-boot
本文介绍了如何使用 spring-boot 在 spring 批处理中设置 JobParameters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了 http://spring.io/guides/gs/batch-processing/ 但它描述了一个没有可配置参数的作业.我正在使用 Maven 来构建我的项目.
I followed the guide at http://spring.io/guides/gs/batch-processing/ but it describes a job with no configurable parameters. I'm using Maven to build my project.
我正在移植我在 XML 中定义的现有作业,并希望通过命令传入 jobParameters.
I'm porting an existing job that I have defined in XML and would like to pass-in the jobParameters through the command.
我尝试了以下方法:
@Configuration
@EnableBatchProcessing
public class MyBatchConfiguration {
// other beans ommited
@Bean
public Resource destFile(@Value("#{jobParameters[dest]}") String dest) {
return new FileSystemResource(dest);
}
}
然后我使用:
mvn clean package
然后我尝试像这样启动程序:
Then I try to launch the program like this :
java my-jarfile.jar dest=/tmp/foo
我收到一个异常说:
[...]
Caused by: org.springframework.expression.spel.SpelEvaluationException:
EL1008E:(pos 0): Field or property 'jobParameters' cannot be found on object of
type 'org.springframework.beans.factory.config.BeanExpressionContext'
谢谢!
推荐答案
我设法通过简单地注释我的 bean 使其工作如下:
I managed to get this working by simply annotating my bean as follows :
@Bean
@StepScope
public Resource destFile(@Value("#{jobParameters[dest]}") String dest) {
return new FileSystemResource(dest);
}
这篇关于如何使用 spring-boot 在 spring 批处理中设置 JobParameters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文