PDA

View Full Version : IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required



dan0
Aug 4th, 2010, 10:13 AM
I believe I've properly configured my data source, however, I continually get the following error:

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required

Below is my bean declaration and class, anyone see what is/could be wrong?



<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.0.121/facility"/>
<property name="username" value="xxxxx"/>
<property name="password" value="xxxxx"/>
</bean>

<bean id="customJdbcDaoImpl" class="com.facility.web.security.CustomJdbcDaoImpl" depends-on="dataSource">
<property name="dataSource" ref="dataSource"/>
</bean>


Note: JdbcDaoImpl has it's own dataSource and jdbcTemplate properties and getters/setters

public class CustomJdbcDaoImpl extends org.springframework.security.core.userdetails.jdbc .JdbcDaoImpl; {
...
}

jamestastic
Aug 4th, 2010, 11:25 AM
I think the error message might be misleading. It appears that jdbcTemplate is required, instead of "dataSource or jdbcTemplate".

See the following, from JdbcDaoSupport, which is extended by JdbcDaoImpl:



@Override
protected void checkDaoConfig() {
if (this.jdbcTemplate == null) {
throw new IllegalArgumentException("'dataSource' or 'jdbcTemplate' is required");
}
}

triqui
Aug 5th, 2010, 03:23 AM
Well, the error is not completely misleading, since in fact JdbcTemplate is created when you set a data source.


public final void setDataSource(DataSource dataSource) {
if (this.jdbcTemplate == null || dataSource != this.jdbcTemplate.getDataSource()) {
this.jdbcTemplate = createJdbcTemplate(dataSource);
initTemplateConfig();
}
}

The createJdbcTemplate method is not going to give any error since it only instantiates a JdbcTemplate and calls setDataSource(dataSource).

So you must be doing something to set the jdbcTemplate variable back to null.
You will need to debug it unless you know where you do it.