java - 如果我们在 Spring Batch 中执行特定方法,如何在 tasklet 中获取作业参数
问题描述
我为执行 3 个不同的作业指定了 3 个步骤。让我们说a,b和c。我在我的spring批处理xml中配置了它。应该这样配置,如果我执行 a,那么只有在成功时才会执行 b,否则会中断,对于 b 也是如此。我还想根据作业参数输入之一执行特定步骤。(如果我得到 b 的输入,那么它将直接执行 b,而不是 a)。我的春季批处理xml:
<batch:job id ="MyJob">
<batch:step id = "a">
<batch:tasklet ref="myJavaClassService" method="callingA"/>
<batch:next on="*" next="b"/>
<batch:next on="FAILED" next="exit"/>
</batch:step>
<batch:step id = "b">
<batch:tasklet ref="myJavaClassService" method="callingB"/>
<batch:next on="*" next="c"/>
<batch:next on="FAILED" next="exit"/>
</batch:step>
<batch:step id = "c">
<batch:tasklet ref="myJavaClassService" method="callingC"/>
<batch:next on="FAILED" next="exit"/>
</batch:step>
<batch:step id = "exit">
<batch:tasklet ref="myJavaClassService" method="exit"/>
</batch:step>
</batch:job>
我的java服务类如下:
@Service("myJavaClassService")
class MyJavaClassService
{
public void callingA() { /* Some Operation --- */ }
public void callingB() { /* Some Operation --- */ }
public void callingC() { /* Some Operation --- */ }
public void exit() { System.exit(1); }
}
我的Java主类如下:
class MyClassMain
{
/*---- some configuration related code ---*/
JobLauncher jobLauncher = (JobLauncher) ctx.getBean("JobLauncher");
Job job = (Job) ctx.getBean("MyJob");
JobParametersBuilder jpd = new JobParametersBuilder();
jpd.addString("firstParam");
jpd.addString("secondParam");
jpd.addString("thirdParam");
JobParameters jp = jpd.toParameters();
JobExecution result = jobLauncher.run(job, jp);
}
我坚持以下几点:
如何获取服务类中的所有作业参数?我尝试实施Tasklet
, ItemPrcoess
,StepListener
等,但没有一个适合我。
如何根据作业参数执行特定步骤,假设我想直接执行“步骤 id = b”?
如何从任何调用方法中给出返回类型,例如我需要从中获取一个输出值callingA
以及我需要传递给callingB
方法的输出值,我该怎么做。
我试图在我的调用方法中使用@BeforeStep
方法获取作业参数,StepExecutionListener
但beforeMethod
没有执行,不知道为什么。例如:我
String first param = executionContext.getStepExecution.getString("firstparam")
在beforeStep
方法中写了一行,但我无法在我的callingA
方法中获取第一个参数值。因此,我意识到,没有一个听众在我的情况下工作。
请注意,我在我的方法中接到了一个电话,callingA
但我无法获得作业参数。
另外,根据我的要求,如果您有任何其他可行的解决方案,我将不胜感激。我对块或任何读写器处理器工作没有任何要求。简单调用 3 种方法,其中包含执行不同 python 作业的代码。
解决方案
推荐阅读
- excel - 将数据从一列复制到范围内的下一个空列
- javascript - 在嵌套循环中处理承诺
- android - 压缩 React Native 应用程序的大小
- c# - 使用子类中的 lambda 表达式
- c# - 尝试调用 Clients.Caller 但它不起作用
- android - ngFor [Angular] [Ionic] [Android] 中损坏的 img 标签
- php - laravel carbon 无法显示默认促销
- c++ - 包含库文件但仍未定义引用
- mysql - mysqldump:无法执行。information_schema 中的未知表“column_statistics”
- html - 如何根据片段创建电话输入