-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Patrick Dumontel opened SPR-1964 and commented
I have a standalone class that extends SimpleJdbcDaoSupport so that I can do a quick import of test data into the database:
public class Migrator extends JdbcDaoSupport {
..
public static void main(String[] args) {
Migrator m = new Migrator();
DriverManagerDataSource ds = new DriverManagerDataSource([connection url, user, etc. go here]);
m.setDataSource(ds);
m.migrate;
}
private void migrate() {
SimpleJdbcTemplate jt = getSimpleJdbcTemplate();
jt.update([some sql here]);
}
Using a debugger, I saw that the simpleJdbcTemplate is null, although the jdbcTemplate that should be wrapped is fine. I worked around this by calling m.afterPropertiesSet(). Could it be that SimpleJdbcDaoSupport only creates the simpleJdbcTemplate if used within an application context? This did not happen in M3, in fact the SimpleJdbcTemplate's source is quite different. This method was in M3 but removed in M4:
protected JdbcTemplate createJdbcTemplate(DataSource dataSource) {
JdbcTemplate jt = new JdbcTemplate(dataSource);
this.simpleJdbcTemplate = new SimpleJdbcTemplate(jt);
return jt;
}
M4 instead has:
protected void checkDaoConfig() {
super.checkDaoConfig();
this.simpleJdbcTemplate = new SimpleJdbcTemplate(getJdbcTemplate());
}
which apparently doesn't get called in a standalone instantiation.
Affects: 2.0 M4