jobParameters не может быть найден для объекта типа BeanExpressionContext

Не удается найти jobParameters для объекта типа BeanExpressionContext

Создайте простое пакетное задание 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);

    }
}

проблема

Появляется сообщение об ошибке «Не удалось найти параметры задания»:

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 не может быть фактически создан до тех пор, пока не начнется «Шаг». Чтобы это исправить, требуется позднее связывание с областью «Step».

job-sample.xml