java.lang.Object | |||
↳ | org.springframework.aop.framework.ProxyConfig | ||
↳ | org.springframework.aop.framework.AbstractSingletonProxyFactoryBean | ||
↳ | org.springframework.transaction.interceptor.TransactionProxyFactoryBean |
Proxy factory bean for simplified declarative transaction handling.
This is a convenient 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 that need to be specified:
PlatformTransactionManager
implementation to use
(for example, a JtaTransactionManager
instance)
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 method pointcut 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>
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This callback is optional: If running in a BeanFactory and no transaction
manager has been set explicitly, a single matching bean of type
PlatformTransactionManager will be fetched from the BeanFactory.
| |||||||||||
Set a pointcut, i.e a bean that can cause conditional invocation
of the TransactionInterceptor depending on method and attributes passed.
| |||||||||||
Set the transaction attribute source which is used to find transaction
attributes.
| |||||||||||
Set properties with method names as keys and transaction attribute
descriptors (parsed via TransactionAttributeEditor) as values:
e.g.
| |||||||||||
Set the transaction manager.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an advisor for this FactoryBean's TransactionInterceptor.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.aop.framework.AbstractSingletonProxyFactoryBean
| |||||||||||
From class
org.springframework.aop.framework.ProxyConfig
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanClassLoaderAware
| |||||||||||
From interface
org.springframework.beans.factory.BeanFactoryAware
| |||||||||||
From interface
org.springframework.beans.factory.FactoryBean
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
|
This callback is optional: If running in a BeanFactory and no transaction manager has been set explicitly, a single matching bean of type PlatformTransactionManager will be fetched from the BeanFactory.
beanFactory | owning BeanFactory (never null ).
The bean can immediately call methods on the factory. |
---|
Set a pointcut, i.e a bean that can cause conditional invocation of the TransactionInterceptor depending on method and attributes passed. Note: Additional interceptors are always invoked.
Set the transaction attribute source which is used to find transaction attributes. If specifying a String property value, a PropertyEditor will create a MethodMapTransactionAttributeSource from the value.
Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly".
Note: Method names are always applied to the target class, no matter if defined in an interface or the class itself.
Internally, a NameMatchTransactionAttributeSource will be created from the given properties.
Set the transaction manager. This will perform actual transaction management: This class is just a way of invoking it.
Creates an advisor for this FactoryBean's TransactionInterceptor.