【发布时间】:2014-02-28 17:24:45
【问题描述】:
我按照http://spring.io/guides/gs/batch-processing/ 的指南进行操作,但它描述了一个没有可配置参数的作业。我正在使用 Maven 构建我的项目。
我正在移植我在 XML 中定义的现有作业,并希望通过命令传入 jobParameters。
我尝试了以下方法:
@Configuration
@EnableBatchProcessing
public class MyBatchConfiguration {
// other beans ommited
@Bean
public Resource destFile(@Value("#{jobParameters[dest]}") String dest) {
return new FileSystemResource(dest);
}
}
然后我使用以下代码编译我的项目:
mvn clean package
然后我尝试像这样启动程序:
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'
谢谢!
【问题讨论】:
-
首先如何设置参数?即
jobParameters[dest]是如何填充的? -
好吧,只需使用 JobParametersBuilder().addString("dest", args[0]).toJobParameters() 在可执行 jar 文件的主类中创建 JobParameters,然后传递结果JobParameters 到 JobLauncher。见docs.spring.io/spring-batch/reference/htmlsingle/…
标签: spring-batch spring-el spring-boot