Java – Spring: replace SqlMapClientTemplate for all clients


I have a number of DAO classes that extend SqlMapClientDaoSupport, and call getSqlMapClientTemplate() to run iBatis queries.

For a particular test, I wish to replace the object returned when each DAO calls getSqlMapClientTemplate(), with my own custom class.

How can I do this?

I know that there is a setSqlMapClientTemplate( org.springframework.orm.ibatis.SqlMapClientTemplate ); however this presents two problems.

1) I wish the replacement to be "global" to my Spring configuration; I don't want to have to call set on each DAO.

2) That setter takes a SqlMapClientTemplate rather than the interface SqlMapClientTemplate implements (SqlMapClientOperations), so it looks as if I need to subclass SqlMapClientTemplate rather than just making my own implementation of the 'SqlMapClientOperation's interface.

How, for a particular Spring configuration, can I globally replace the SqlMapClientTemplate returned from all calls to getSqlMapClientTemplate()?


Best Solution

Either use some sort of AOP or have all of the bean definitions in your context extend an abstract definition:

<bean id="baseDao" abstract="true">
    <property name="sqlMapClientTemplate" ref="yourNewClientTemplate"/>

<bean id="specificDao" class="com.companyname.class" parent="baseDao" >