2017-05-19 7 views
0

RowMapper를 구현하는 BusinessRowMapper 클래스는 PostGres JSONB 객체를 Java 객체로 변환한다.RowMapper를 구현하는 클래스에서 Spring 관리 빈 삽입

BusinessRowMapper implements RowMapper<PersonDetails> 

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; 
    } 
} 

인 mapRow

지금 우선, 나는 봄이 BusinessRowMapper 콩에서 PersonUtility 콩의 주입보다는 BusinessRowMapper에 생성자 인수로 유틸리티 빈 전달을 관리 어떻게해야합니까?

getNamedParameterJdbcTemplate().query(
         ConstantsV4.RETRIEVE_PERSON_DETAIL_QUERY, params, 
         new BusinessRowMapper(utility)); 

답변

1

당신은 클래스를 통해 @component를 추가 스프링 빈으로 PersonUtility 클래스를 정의 할 수 있습니다.

그럼 당신은 작동하지 않았다 BusinessRowMapper

@Component 
    public class BusinessRowMapper implements RowMapper<PersonDetails> { 

    @Autowired 
    private PersonUtility utils; 


    ... 


    } 
+0

의 필드를 autowire하기 수 있습니다. 그리고이 Mapper 빈을 에서 호출하는 방법 - getNamedParameterJdbcTemplate(). query ( ConstantsV4.RETRIEVE_PERSON_DETAIL_QUERY, params, new BusinessRowMapper (유틸리티)); – user842122