春季:为所有客户端替换SqlMapClientTemplate吗? [英] Spring: replace SqlMapClientTemplate for all clients?

查看:164
本文介绍了春季:为所有客户端替换SqlMapClientTemplate吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多DAO类扩展了SqlMapClientDaoSupport,并调用getSqlMapClientTemplate()运行iBatis查询.

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

对于特定测试,我希望将每个DAO调用getSqlMapClientTemplate()时返回的对象替换为我自己的自定义类.

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

我该怎么做?

我知道有一个setSqlMapClientTemplate( org.springframework.orm.ibatis.SqlMapClientTemplate );但是,这带来了两个问题.

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

1)我希望替换对我的Spring配置是全局"的;我不想在每个DAO上都调用set.

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)该setter使用的是SqlMapClientTemplate而不是SqlMapClientTemplate实现的接口(SqlMapClientOperations),因此,似乎我需要继承SqlMapClientTemplate的类,而不是仅自己编写'SqlMapClientOperation'接口的实现

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.

对于特定的Spring配置,如何全局替换从所有对getSqlMapClientTemplate()的调用返回的SqlMapClientTemplate?

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

谢谢.

推荐答案

要么使用某种AOP,要么使上下文中的所有bean定义都扩展一个抽象定义:

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>

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

这篇关于春季:为所有客户端替换SqlMapClientTemplate吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆