Java Reference
In-Depth Information
object. In an enterprise Java application, inter-
ceptors can be used for a number of purposes,
including security, database connection man-
agement, and transaction management.
In this example application, we can config-
ure the Spring bean factory to wrap Transfer-
Facade with a proxy that manages transactions.
To do that, we must define several beans,
including those shown in figure 1.5. This dia-
gram shows the TransferFacade bean, along
with PlatformTransactionManager , Trans-
actionInterceptor, and BeanNameAutoProxy-
Creator , the Spring classes that make Transfer-
Facade transactional.
The BeanNameAutoProxyCreator bean wraps
TransferFacade with a TransactionInterceptor , which manages transactions using
the PlatformTransactionManager . The PlatformTransactionManager in this exam-
ple is implemented by the HibernateTransactionManager class, which uses the
Hibernate Transaction interface to begin, commit, and roll back transactions. List-
ing 1.1 shows an excerpt from the XML configuration file that defines these beans.
BeanName
AutoProxy
Creator
Transaction
Interceptor
TransferFaçade
Platform
Transaction
Manager
Figure 1.5 The Spring bean definitions
required to make TransferFacade
transactional
Listing 1.1
Configuring Spring transaction management
<beans>
B Define the
TransferFacade
<bean id="TransferFacade"
class="TransferFacadeImpl">
</bean>
C
Define the Hibernate
PlatformTransactionManager
<bean id="PlatformTransactionManager"
class="org.springframework.orm.
bbbbbbbbb b
hibernate3.HibernateTransactionManager">
</bean>
D Define the
TransactionInterceptor
<bean id="TransactionInterceptor"
class="org.springframework.transaction.
bbbbbbbbb b
interceptor.TransactionInterceptor">
<property name="transactionManager"
ref="PlatformTransactionManager"/>
<property name="transactionAttributeSource"
value="*=PROPAGATION_REQUIRED"/>
</bean>
 
Search WWH ::




Custom Search