Spring/기타

Spring 오류) JDBCSupport 연결 시 DI 시점 오류

읽히는 블로그 2024. 8. 13. 22:06
Cannot invoke "org.springframework.jdbc.core.JdbcTemplate.query(String, org.springframework.jdbc.core.RowMapper)" because the return value of "pack.model.DAO.getJdbcTemplate()" is null

 

위와 같은 오류가 나오는 이유는 DAO에서 주입 시점때문에 발생하는 문제이다.

 

 

 

 

 

 

정리해보자면 필드로 의존성을 주입하면 jdbcSupport가 생성되는 시점에 필드 주입이 null일 가능성이 있다.

생성자 주입을 해서 안정적으로 setDataSource 메서드 사용시 매개변수를 넣자.