为什么 Spring 有 JdbcDaoSupport 类,但没有类似的 JmsSupport 类?
为什么Spring框架有类JdbcDaoSupport
需要 数据源
并创建一个 < code>JdbcTemplate 内部,但没有类似的类 JmsSupport
可能需要 JMS ConnectionFactory
并创建一个 JmsTemplate
?
据我了解,类 JdbcDaoSupport
的目的是消除应用程序上下文中 JdbcTemplate
的冗余实例(每个 DataSource
实例一个)。相反,容器创建应用程序 DAO 的实例,每个实例都派生自 JdbcDaoSupport
,接受唯一的 DataSource
并将此 DataSource
提供给 < code>JdbcDaoSupport 父实例,该实例又将其提供给其内部 JmsTemplate
。
为什么 Spring 不提供一个类似的类 JmsSupport
来减少应用程序上下文中 JmsTemplate
实例的数量?
Why does the Spring Framework have class JdbcDaoSupport
that requires a DataSource
and creates a JdbcTemplate
internally, but has no analagous class JmsSupport
that might require a JMS ConnectionFactory
and create a JmsTemplate
?
As I understand, the purpose of class JdbcDaoSupport
is to eliminate redundant instances of JdbcTemplate
(one per DataSource
instance) in an application context. Instead, the container creates instances of an application DAO, each of which derives from JdbcDaoSupport
, accepts a unique DataSource
and provides this DataSource
to the JdbcDaoSupport
parent instance which in turn provides it to its internal JmsTemplate
.
Why doesn't Spring provide an analogous class JmsSupport
that would serve to reduce the number of JmsTemplate
instances in an application context?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JdbcDaoSupport
只不过是还扩展了DaoSupport
的JdbcTemplate
的用户。它为 JDBC 提供了 DAO 设计模式的基本实现,就像其他类为 Hibernate、JPA 等所做的那样。很多人不使用 DAO 范式;相反,他们定义了一个单例
JdbcTemplate
,将其直接注入到服务层中。对于 JMS,据我所知,没有像 DAO 这样的通用设计模式,并且“
JmsTemplate
的用户”没有其他可能的变体。您应该使用单例JmsTemplate
:仅此而已。JdbcDaoSupport
is little more than a user of aJdbcTemplate
that also extendsDaoSupport
. It provides a base implementation of the DAO design pattern for JDBC, like other classes do for Hibernate, JPA, and others.A lot of people don't use the DAO paradigm; instead, they define a singleton
JdbcTemplate
that they inject directly into their service layer.For JMS, there is - as far as I know - no generic design pattern like the DAO, and there's no other possible variations on "a user of
JmsTemplate
". You should use a singletonJmsTemplate
: there's nothing more to it.