タイプBeanExpressionContextのオブジェクトでjobParametersが見つかりません
単純なSpringバッチジョブを作成して、データをcsvファイルに書き込みます。 csvファイル名は、ジョブのパラメーターのパスに依存し、Spring ELによって解釈されます。
job-sample.xml
ジョブの上の単体テスト:
public class TestSampleJob extends AbstractTestNGSpringContextTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Test public void launchJob() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("pid", "10").toJobParameters(); JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobParameters); Assert.assertEquals(jobExecution.getStatus(), BatchStatus.COMPLETED); } }
問題
「jobParametersが見つかりません」というエラーメッセージが表示されます。
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' at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208) at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:72) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
溶液
jobParameters
Beanは、「ステップ」が開始されるまで実際にはインスタンス化できません。 これを修正するには、「Step」のスコープを持つ遅延バインディングが必要です。
job-sample.xml