I implemented ItemReader with JdbcTemplate .
The problem is that read()
is being invoked in infinite loop.
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 batch configuration:
<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>