Category Archives: datasource

Caused by: java.lang.IllegalArgumentException: ‘dataSource’ or ‘jdbcTemplate’ is required

A Simple DAO class extends JdbcDaoSupport, but, unable to inject or @autowired a “dataSource”, the method setDataSource is final, can’t override.

Solution

To quickly fix it, uses @PostConstruct to inject the dataSource like this :

@Repository
public class UserDetailsDaoImpl extends JdbcDaoSupport implements UserDetailsDao {

@Autowired
private DataSource dataSource;

@PostConstruct
private void initialize() {
setDataSource(dataSource);
}

}

Alternatively, create an own implementation of JdbcDaoSupport class, and do whatever you want. Dive inside the source code of JdbcDaoSupport, it’s just a simple helper class to create a jdbcTemplate.


Source :- https://www.mkyong.com/spring/how-to-autowire-datasource-in-jdbcdaosupport/

111 total views, no views today