自定义项目读取器抛出ReaderNotOpenException

时间:2014-03-08 15:12:12

标签: spring-batch

我有一个自定义项目阅读器,如下所示

    class MyReader implements ItemReader<MyBean>, ItemStream{

    SingleItemPeekableItemReader<MyBean> myBeanPeekableReader;

    public SingleItemPeekableItemReader<MyBean> getMyBeanPeekableReader() {
        return myBeanPeekableReader;
    }

    public void setMyBeanPeekableReader(
            SingleItemPeekableItemReader<MyBean> myBeanPeekableReader) {
        this.myBeanPeekableReader = myBeanPeekableReader;
    }

    @Resource
    public void caller(ItemReader<MyBean> myJdbcReader){
        myBeanPeekableReader.setDelegate(myJdbcReader);
    }


    @Override
        public void close() throws ItemStreamException {
            myBeanPeekableReader.close();
        }

        @Override
        public void open(ExecutionContext arg0) throws ItemStreamException {
            myBeanPeekableReader.open(arg0);
        }

        @Override
        public void update(ExecutionContext arg0) throws ItemStreamException {
            // TODO Auto-generated method stub

        }

扩展JdbcCursorItemReader的类:

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

@Component("myJdbcReader")
public class MyJdbcReader extends JdbcCursorItemReader<MyBean> {


    private String sql = "Select * from mytable";

    MyJdbcReader(){
        super.setSql(sql);
    }

    @Override
    @Resource
    public void setDataSource(DataSource dataSource){
        super.setDataSource(dataSource);
    }

    @Override
    @Resource
    public void setRowMapper(RowMapper myRowMapper){
        super.setRowMapper(myRowMapper);
    }

    @Override
    @Resource
    public void setPreparedStatementSetter(PreparedStatementSetter myPrepSetter){
        super.setPreparedStatementSetter(myPrepSetter);
    }

}

即使在实现了ItemStream之后,它也会抛出异常的ReaderNotFound ..而有人会建议我出错的地方。

0 个答案:

没有答案