Spring Batch:RowMapper没有获得Autowuired

时间:2012-07-04 14:27:52

标签: spring-batch

我有这个配置:

<bean id="reader" class="com.company.MyReader" scope="prototype">
    <property name="dataSource" ref="dataSource"/>
    <property name="sql" value="select * from dummy"/>
    <property name="rowMapper" ref="rowMapper"/>
    <property name="verifyCursorPosition" value="false"/>
</bean>

<bean id="rowMapper" class="com.company.MyRowMapper>
    <property name="firstName" value="hillary/>
</bean>

MyRowMapper实现 org.springframework.jdbc.core.RowMapper

MyReader扩展 org.springframework.batch.item.database.JdbcCursorItemReader

在MyReader中,调用 super.doRead(),这将返回MyRowMapper对象。 但是,这些对象没有被容器自动装配 - 属性firstName返回null。请注意,Spring容器正在按预期自动装配MyReader。

需要做什么才能让RowMapper自动装配?

非常感谢!

1 个答案:

答案 0 :(得分:1)

您是否注释了MyReader以通知Spring它需要MyRowMapper的实例?

     public class com.company.MyReader{

        @Autowired
        private MyRowMapper mapper;


        public void setMyRowMapper(MyRowMapper newMapper){
            this.mapper = newMapper;
        }
    }