编程语言
首页 > 编程语言> > java-无限循环中的ItemReader reader()

java-无限循环中的ItemReader reader()

作者:互联网

我用JdbcTemplate实现了ItemReader.

问题在于read()在无限循环中被调用.

public class MyReader implements ItemReader<Col>, InitializingBean {
    private JdbcTemplate jdbcTemplate;
    private RowMapper<Col> rowMapper;
    private String sql;
    private DataSource dataSource;

public Col read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
     Col col = jdbcTemplate.queryForObject(sql,null, rowMapper);            
     return col;
    }

}

Spring批处理配置:

<chunk reader="itemReader" writer="itemWriter"
            processor="itemProcessor" commit-interval="1" />


<bean id="itemReader"
    class="batch.MyReader"
    scope="step">
    <property name="dataSource" ref="dataSource" />
    <property name="sql" value="#{stepExecutionContext[sql]}" />
    <property name="rowMapper">
        <bean class="batch.ColMapper" />
    </property>
</bean>

解决方法:

这就是Spring Batch步骤的工作方式:ItemReader.read()方法将被调用,直到返回null.

标签:spring-batch,spring,java
来源: https://codeday.me/bug/20191120/2046901.html