2017-07-20 29 views
0

我有一個春天批處理過程,從表中讀取值並將其寫入到自定義寫入器。 我正在使用spring scheduler來執行作業。下面是我的春季調度程序的配置。 但我在閱讀器中獲得空值。我在日誌中沒有看到任何錯誤,我的工作運行良好,但月份的值爲空。 (然而,用我的參數值的方式在我的查詢,以便它適用於一般的查詢。)空值在我的自定義閱讀器在春季批次

我的計劃:

JobParameters param = new JobParametersBuilder() 
        .addLong("time", System.currentTimeMillis()) 
        .addString("date", "07-12-2017") // will be from a variable 
        .addString("month", "june")  // will be from a variable 
        .toJobParameters(); 

JobExecution execution = jobLauncher.run(job, param); 

我的讀者:

@Bean 
@StepScope 
public ItemReader<Bill> reader(@Value("#{jobParameters[month]}") String month) throws Exception { 

    System.out.println("*****************************"); 
    System.out.println("month ::::::: "+month); 
    System.out.println("*****************************"); 

    // My awesome database query here, where I will be using month. 

上面月份即將爲空。

我的批量配置:

@Bean 
public Job CreateBillJob(JobCompletionNotificationListener listener) throws Exception { 

    return jobBuilderFactory.get("createBill") 
      .incrementer(new RunIdIncrementer()) 
      .listener(listener) 
      .flow(step1()) 
      .end() 
      .build(); 
} 

private static final String OVERRIDDEN_BY_EXPRESSION = null; 

@Bean 
public Step step1() throws Exception { 
    return stepBuilderFactory.get("step1") 
      .<Bill, Bill> chunk(500) 
      .reader(billDataReader.reader(OVERRIDDEN_BY_EXPRESSION)) 
      .processor(processor()) 
      .writer(fileWriter) 
      .build(); 
} 

任何幫助真的讚賞。謝謝你們。

回答

0

我認爲,有一個單引號周圍是否缺少month@Value("#{jobParameters['month']}"代替@Value("#{jobParameters[month]}"

+0

謝謝@SabirKhan,您的答覆。我嘗試過,但仍然沒有工作,相同的空白即將到來。 – Karthik

+0

我知道這看起來很奇怪,但是我將閱讀器從其單個文件移回我的批處理配置文件,並且它工作正常。這是正確的方法,我不確定。 – Karthik