I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method on it. How can I wire datasource to it using annotation @autowire?
You can use @Autowired on a constructor or on a method with another name. Personally I prefer the latter option.
@Autowired
public MyClass(DataSource dataSource) {
super();
setDataSource(dataSource);
}
@Autowired
public void setDs(DataSource dataSource) {
setDataSource(dataSource);
}
Another option is this:
@Autowired
private DataSource ds;
@Override
protected void initDao() throws Exception {
super.initDao();
setDataSource(ds);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With