[英]Read value from application.properties into Spring Batch Reader?
I am developing Spring Batch Oracle 12c example, in this reader, I wanted to pass value 60 as a placeholder, if this value changes in future, I should be able to handle it from the application.properties file rather than using it in the sql query as hardcode value. 我正在开发Spring Batch Oracle 12c示例,在此读者中,我想传递值60作为占位符,如果将来该值发生变化,我应该能够从application.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>
I was able to do that using below code. 我能够使用下面的代码做到这一点。
<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>
Also I used the below code in the Step Execution: 我还在步骤执行中使用了以下代码:
ExecutionContext executionContext = new ExecutionContext();
executionContext.put("days60", 60);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.