Results 1 to 2 of 2

Thread: RowMapper is not getting Autowired by Spring

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Question RowMapper is not getting Autowired by Spring

    I have this configuration:
    Code:
    <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 implements org.springframework.jdbc.core.RowMapper

    MyReader extends org.springframework.batch.item.database.JdbcCursor ItemReader

    Within MyReader, super.doRead() is called, and this returns MyRowMapper objects.
    However, these objects are not getting autowired by the container - the property firstName comes back as null. Note that MyReader is being autowired by the Spring container as expected.

    What needs to be done so that RowMapper is autowired?
    Thanks very much!
    Last edited by rosalie; Jul 4th, 2012 at 10:23 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I would expect a nice stacktrace if there wouldn't be a rowmapper so I would first check your rowmapper implementation, also be aware that you are injecting a singleton in a non singleton.

    Also the read method should return the objects created by the rowmapper implementation NOT rowmapper implementations.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •