Author(s)Juergen Hoeller, Dmitriy Kopylenko, Rod Johnson
Proxy factory bean for simplified declarative transaction handling.
Alternative to a standard AOP ProxyFactoryBean with a separate
TransactionInterceptor definition.
This class is intended to cover the typical case of declarative
transaction demarcation: namely, wrapping a singleton target object with a
transactional proxy, proxying all the interfaces that the target implements.
There are three main properties to be specified:
"transactionManager": the PlatformTransactionManager implementation to use
(for example, a JtaTransactionManager instance)
"target": the target object that a transactional proxy should be created for
"transactionAttributes": the transaction attributes (for example, propagation
behavior and "readOnly" flag) per target method name (or method name pattern)
If the "transactionManager" property is not set explicitly and this FactoryBean
is running in a ListableBeanFactory, a single matching bean of type
PlatformTransactionManager will be fetched from the BeanFactory.
In contrast to TransactionInterceptor, the transaction attributes are
specified as properties, with method names as keys and transaction attribute
descriptors as values. Method names are always applied to the target class.
Internally, a TransactionInterceptor instance is used, but the user of this
class does not have to care. Optionally, a MethodPointcut can be specified
to cause conditional invocation of the underlying TransactionInterceptor.
The "preInterceptors" and "postInterceptors" properties can be set to add
additional interceptors to the mix, like PerformanceMonitorInterceptor or
HibernateInterceptor/JdoInterceptor.
HINT: This class is often used with parent/child bean definitions.
Typically, you will define the transaction manager and default transaction
attributes (for method name patterns) in an abstract parent bean definition,
deriving concrete child bean definitions for specific target objects.
This reduces the per-bean definition effort to a minimum.
This class is intended to cover the typical case of declarative transaction demarcation: namely, wrapping a singleton target object with a transactional proxy, proxying all the interfaces that the target implements.
There are three main properties to be specified:
If the "transactionManager" property is not set explicitly and this FactoryBean is running in a ListableBeanFactory, a single matching bean of type PlatformTransactionManager will be fetched from the BeanFactory.
In contrast to TransactionInterceptor, the transaction attributes are specified as properties, with method names as keys and transaction attribute descriptors as values. Method names are always applied to the target class.
Internally, a TransactionInterceptor instance is used, but the user of this class does not have to care. Optionally, a MethodPointcut can be specified to cause conditional invocation of the underlying TransactionInterceptor.
The "preInterceptors" and "postInterceptors" properties can be set to add additional interceptors to the mix, like PerformanceMonitorInterceptor or HibernateInterceptor/JdoInterceptor.
HINT: This class is often used with parent/child bean definitions. Typically, you will define the transaction manager and default transaction attributes (for method name patterns) in an abstract parent bean definition, deriving concrete child bean definitions for specific target objects. This reduces the per-bean definition effort to a minimum.
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <bean id="myProxy" parent="baseTransactionProxy"> <property name="target" ref="myTarget"/> </bean> <bean id="yourProxy" parent="baseTransactionProxy"> <property name="target" ref="yourTarget"/> </bean>