从application.properties中读取值到Spring Batch Reader中吗?

时间:2018-07-29 21:07:18

标签: java spring-batch

我正在开发 Spring Batch Oracle 12c 示例,在此阅读器中,我希望传递值60作为占位符,如果将来该值发生变化,我应该能够从应用程序中处理它.properties文件,而不是在sql查询中将其用作硬编码值。

<bean id="myReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
<property name="dataSource" ref="dataSource" />
<property name="verifyCursorPosition" value="false" />
<property name="fetchSize" value="50" />
<property name="sql">
    <value>
            <![CDATA[
            SELECT data.Acc_NUM, data.FD_NUM FROM FD_DATA data, BATch_JOB_RUN B,
            CASE WHEN (data.crte_dt + 60 > sysdate) then 'YES' else 'NO' End DONT_CONSIDER
            WHERE data.ONLINE_ID is NULL and data.updt_dt > B.RUN_DT    
            ]]>
    </value>
</property>
<property name="rowMapper">
    <bean class="com.XXX.XXX.mapper.BankDataVOMapper"
        scope="step" />
</property>
</bean>

1 个答案:

答案 0 :(得分:0)

我能够使用下面的代码来做到这一点。

<bean id="myReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
<property name="dataSource" ref="dataSource" />
<property name="verifyCursorPosition" value="false" />
<property name="fetchSize" value="50" />
<property name="sql">
    <value>
            <![CDATA[
            SELECT data.Acc_NUM, data.FD_NUM FROM FD_DATA data, BATch_JOB_RUN B,
            CASE WHEN (data.crte_dt + (#{stepExecutionContext[days60]}) > sysdate) then 'YES' else 'NO' End DONT_CONSIDER
            WHERE data.ONLINE_ID is NULL and data.updt_dt > B.RUN_DT    
            ]]>
    </value>
</property>
<property name="rowMapper">
    <bean class="com.XXX.XXX.mapper.BankDataVOMapper" scope="step" />
</property>
</bean>

我还在步骤执行中使用了以下代码:

ExecutionContext executionContext = new ExecutionContext();
executionContext.put("days60", 60);