spring-batch - 如何在spring-batch中将参数从作业传递到FlowStep?
问题描述
在一个特定的 spring-batch 作业中,我使用 a Flow
(因为它是可重用的步骤序列)作为Step
.
我必须将一组参数传递给Flow
.
我怎么做?
我的工作定义如下:
@Component
public class MyJob {
@Bean
public Job myJob(@Qualifier("myFlowStep") Flow myFlow) {
return jobBuilderFactory.get("myJob").incrementer(new RunIdIncrementer())
.start(someFirstStep())
.next(myFlowStep(myFlow)).
.build();
}
...
@Bean
public Step myFlowStep(Flow myFlow) {
// Need to pass parameters to the flow
FlowStepBuilder flowStepBuilder = stepBuilderFactory.get("myFlowStep").flow(myFlow);
return flowStepBuilder.build();
}
...
}
解决方案
您可以将流 bean 定义步骤设置为范围并使用作业参数的后期绑定:
@Bean
@StepScope
public Flow myFlow(@Value("#{jobParameters['name']}") String name) {
// use job parameter name here
return null;
}
@Bean
public Step myFlowStep(Flow myFlow) {
// Need to pass parameters to the flow
FlowStepBuilder flowStepBuilder = stepBuilderFactory.get("myFlowStep").flow(myFlow);
return flowStepBuilder.build();
}
推荐阅读
- ruby-on-rails - LoadError:无法加载这样的文件——faker
- wordpress - 如何解决wordpress中的http 500错误?
- graphics - 如何在 xamarin for android 中实现 GWS 库?
- java - 如何在 @PersistenceContext 中不提供单位名称的情况下访问实体管理器?
- android - Dagger/MissingBinding:如果没有 @Inject 构造函数或 @Provides-annotated 方法,则无法提供 android.app.Application
- python - 用python在图像中插值被涂黑的ROI
- cmake - 如何将 `include-what-you-use` 警告视为 `cmake` 的错误
- c# - App.Config 中的自定义部分,ConfigurationManager 停止工作
- c++ - G++ 4.9.2 和 8.2.0 - 最终二进制文件的依赖项,默认 lib 路径搜索 ./../lib 目录(隐式 RPATH 问题)
- java - 如何使用包含 java 文件的 jar 文件?