如何手动使 Spring Batch 作业失败?

Cod*_*lue 5 java spring spring-batch

这是我为了测试目的需要做的事情。我需要一种根据某些预设条件(例如处理的项目数)随时使 Spring Batch 作业失败的方法。但是,到目前为止,我还没有找到类似的东西。

我发现 Spring Batch 有这样的东西 -

<step id="step1" parent="s1" next="step2">

<step id="step2" parent="s2">
    <fail on="FAILED" exit-code="EARLY TERMINATION"/>
    <next on="*" to="step3"/>
</step>

<step id="step3" parent="s3">
Run Code Online (Sandbox Code Playgroud)

但我正在寻找的是这样的——

public void myJobFailingMethod()
 {
    if(conditionsMatch())
     {
        // fail the job 
     }  
 }
Run Code Online (Sandbox Code Playgroud)

这该怎么做?

更新:作业也可能在步骤之外失败。

Cod*_*lue 4

public void myJobFailingMethod()
{
    if(conditionsMatch())
    {
        throw new CustomJobFailingException(); // create this exception class.
                                               // It will fail the job.
    }  
}
Run Code Online (Sandbox Code Playgroud)