Why does Spring have class JdbcDaoSupport, but no analagous class JmsSupport?
-
26-10-2019 - |
Question
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?
Solution
JdbcDaoSupport
is little more than a user of a JdbcTemplate
that also extends DaoSupport
. 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 singleton JmsTemplate
: there's nothing more to it.