Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring batch 项目读取器中的Spring批处理作业参数_Spring Batch - Fatal编程技术网

Spring batch 项目读取器中的Spring批处理作业参数

Spring batch 项目读取器中的Spring批处理作业参数,spring-batch,Spring Batch,我的参数(workingDirectory)总是null,我不明白为什么? 我正在使用作业启动程序启动作业。 我在数据库中看到了job参数,但它没有被注入到我的阅读器中 @Component("customerReader") @StepScope public class CustomReader implements ItemReader<Customer> { @Value("#{jobParameters['workingDirectory']}") protect

我的参数(
workingDirectory
)总是
null
,我不明白为什么?
我正在使用作业启动程序启动作业。
我在数据库中看到了job参数,但它没有被注入到我的阅读器中

@Component("customerReader")
@StepScope
public class CustomReader implements ItemReader<Customer> {

  @Value("#{jobParameters['workingDirectory']}")
  protected String workingDirectory;

  private BufferedReader reader;
  protected ObjectMapper objectMapper = new ObjectMapper();
  private int fileIdx = 1;


  @Override
  public Customer read() throws IOException {

    if(reader == null) {
      reader = new BufferedReader(new FileReader(new File(workingDirectory + "output1.json")));
    }
    String line = reader.readLine();
    if (line == null) {
      try {
        fileIdx++;
        reader = new BufferedReader(
            new FileReader(new File(workingDirectory + "output" + fileIdx + ".json")));
      }
      catch (FileNotFoundException ex) {
        return null;
      }
      line = reader.readLine();
    }
    return objectMapper.readValue(line, Customer.class);
  }
}
这是我的读者

@Component("customerReader")
@StepScope
public class CustomReader implements ItemReader<Customer> {

  @Value("#{jobParameters['workingDirectory']}")
  protected String workingDirectory;

  private BufferedReader reader;
  protected ObjectMapper objectMapper = new ObjectMapper();
  private int fileIdx = 1;


  @Override
  public Customer read() throws IOException {

    if(reader == null) {
      reader = new BufferedReader(new FileReader(new File(workingDirectory + "output1.json")));
    }
    String line = reader.readLine();
    if (line == null) {
      try {
        fileIdx++;
        reader = new BufferedReader(
            new FileReader(new File(workingDirectory + "output" + fileIdx + ".json")));
      }
      catch (FileNotFoundException ex) {
        return null;
      }
      line = reader.readLine();
    }
    return objectMapper.readValue(line, Customer.class);
  }
}

我认为这不是spring批处理的问题,而是spring配置的问题。我看到
值(“#{jobParameters['workingDirectory']}”)
为空,因此spring可能无法将此属性注入bean。请检查spring上下文的初始化,并阅读关于
@Value
javadoc的内容