Java Reference
In-Depth Information
Strategies with the Spring Framework
In a Java EE application, an SLSB implements the domain service for a remote client. The
SLSB is the most useful EJB component and can be used extensively for remoting and
transaction support. However, as shown in Chapter 4, writing and maintaining an EJB is
cumbersome because it involves a lot of classes and metadata. Also, they have little
importance if your application needs to run out of an EJB container or in a web con-
tainer. Moreover, a session facade intercepts only a remote business logic request, so in
a strict sense the application service actually implements the domain service.
With the Spring Framework, it is possible to provide declarative transaction support
even to POJO application service components. This makes an application highly
portable. You can now deploy this application in a web container with just a few configu-
ration changes. This application, with the POJO domain service, can also continue to run
in the EJB container and subscribe to container-managed transactions. Thus, with the
Spring Framework, you do not need an EJB to support transactions.
The Spring Framework neither implements any transaction monitor nor tries to
directly manage transactions. Instead, it delegates to the underlying transaction imple-
mentation through an abstraction called a platform transaction manager . There are
transaction manager implementations for most of the widely used platforms—JDBC,
object-relational mapping such as Hibernate and TopLink, JTA, JCA, and all major appli-
cation servers. In the next few sections, I will review some frequently used transaction
managers.
Plain JDBC Transactions
The DataSourceTransactionManager handles all the transactional requirements if straight
JDBC or Spring DAO is being used in the application. It can be configured in the Spring
application context as shown in Listing 6-26.
Listing 6-26. transaction-config.xml
<beans>
<bean id="datasourceTransactionManager" class="org.springframework. å
jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<beans>
 
Search WWH ::




Custom Search