3

I have a class BusinessRowMapper that implements RowMapper to convert PostGres JSONB object to Java object.

BusinessRowMapper implements RowMapper<PersonDetails>

it overrides mapRow

   public class BusinessRowMapper implements RowMapper<PersonDetails> {

    private PersonUtility utils;

    public BusinessRowMapper(PersonUtility utils) {
        super();
        this.utils = utils;
    }


    public PersonDetails mapRow(final ResultSet rs, final int rowNum) throws SQLException {
        PersonDetails personDetail = utils.unMarshallAndConvertData(rs
                .getString(ConstantsV4.COLUMN_CUST_DTLS_JSON_DOC));
        return personDetail;
    }
}

Now, How do I do Spring managed Injection of PersonUtility Bean in this BusinessRowMapper bean rather than passing the utility bean as constructor argument to BusinessRowMapper?

getNamedParameterJdbcTemplate().query(
                        ConstantsV4.RETRIEVE_PERSON_DETAIL_QUERY, params,
                        new BusinessRowMapper(utility));
user842122
  • 295
  • 2
  • 4
  • 18

1 Answers1

1

You can define PersonUtility class as spring bean adding @component over the class.

Then you can autowire the field in BusinessRowMapper

@Component 
    public class BusinessRowMapper implements RowMapper<PersonDetails> { 

    @Autowired 
    private PersonUtility utils; 


    ... 


    } 
Denis Ismailovski
  • 311
  • 1
  • 7
  • 15
  • Didn't work. And, How do you invoke this Mapper bean from - getNamedParameterJdbcTemplate().query( ConstantsV4.RETRIEVE_PERSON_DETAIL_QUERY, params, new BusinessRowMapper(utility)); – user842122 May 19 '17 at 13:49