ItemReader reader() in infinite loop

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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>

回答1:

That's the way a Spring Batch step works: the ItemReader.read() method will be called until it returns null.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!