我用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>
答案 0 :(得分:3)
这就是Spring Batch步骤的工作方式:ItemReader.read()方法将被调用,直到它返回null。