简体   繁体   English

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

[英]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.

相关问题 从 .txt 读取值到 application.properties - read value from .txt to application.properties Spring Boot和Batch:基于application.properties值阻止批处理开始 - Spring Boot and Batch: Stop batch from starting based on application.properties value 作为参数值从 application.properties 在类级别 Spring Batch 传递 - Pass as parameter value from application.properties at class level Spring Batch 如何在 spring 引导中读取构造函数内的 application.properties 值? - How to read application.properties value inside the constructor in spring boot? Spring Boot不会从application.properties文件中读取默认值 - Spring Boot doesn't read the default value from the application.properties file 春季启动:从“ application.properties”读取文件路径 - Spring boot: Read a file PATH from “application.properties” Spring Redis - 从application.properties文件中读取配置 - Spring Redis - Read configuration from application.properties file Java Spring无法从application.properties中正确读取值 - Java spring does not read properly values from application.properties spring-从application.properties文件内部读取环境变量 - spring - read environment variables from inside the application.properties file spring 引导中的@value 未从 application.properties 提供值 - @value in spring boot not giving value from application.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM