Thursday 13 October 2016

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/

2 comments:

Spring boot with CORS

CORS (Cross-Origin Resource Sharing) errors occur when a web application running in a browser requests a resource from a different domain or...