传递Spring数据中的参数

我想知道如何将参数传递给bean.xml。

如果我在bean.xml中这样写,它按预期工作

        

但如果我这样写,我会收到错误

   

我的bean.xml

                        

AgingScheduler

  JobParametersBuilder builder = new JobParametersBuilder(); builder.addDate("date", new Date()); builder.addString("fileName", "AgingReporting_" + PropertiseUtil.settlementDateyyyyMMdd()); builder.addString("edcbatchStatus","A").toJobParameters(); 

错误

 Job failed with following exceptions exception :Failed to initialize the reader 

你好约翰,

您可以创建JdbcCursorItemReader的子类,将#{jobParameters [‘edcbatchStatus’]}设置为单独的参数。 然后使用Springs InitializingBean设置Sql属性。 这样的事怎么样?

 class EdcBatchStatusItemReader extends org.springframework.batch.item.database.JdbcCursorItemReader implements org.springframework.beans.factory.InitializingBean { protected String batchStatus; public void getBatchStatus(String batchStatus) { this.batchStatus = batchStatus; } public void afterPropertiesSet() { setSql("SELECT r.EDCBATCH_OPEN_DATETIME As openDate FROM rev_acq_edcbatch r WHERE r.EDCBATCH_STATUS ='" + batchStatus + "'"); } } 

然后将sql从bean定义中删除并使用setBatchStatus代替:

         

祝福马克

PS你的代码不起作用的原因是Spring认为#{jobParameters [‘edcbatchStatus’]}是SQL的一部分并且不解释它。 如果您将其作为字段的完整值传递它应该有效,假设语法正确。