Top Description Fields Constructors Methods
org.springframework.transaction.interceptor

public Class TransactionProxyFactoryBean

extends AbstractSingletonProxyFactoryBean
implements BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware
Annotations
@SuppressWarnings:serial
Imports
java.util.Properties, org.springframework.aop.Pointcut, org.springframework.aop.framework.AbstractSingletonProxyFactoryBean, .ProxyFactory, org.springframework.aop.support.DefaultPointcutAdvisor, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .FactoryBean, .ListableBeanFactory, org.springframework.lang.Nullable, org.springframework.transaction.PlatformTransactionManager

Proxy factory bean for simplified declarative transaction handling. This is a convenient alternative to a standard AOP org.springframework.aop.framework.ProxyFactoryBean with a separate TransactionInterceptor definition.

HISTORICAL NOTE: This class was originally designed 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. However, in Spring versions 2.0 and beyond, the functionality provided here is superseded by the more convenient tx: XML namespace. See the declarative transaction management section of the Spring reference documentation to understand modern options for managing transactions in Spring applications. For these reasons, users should favor the tx: XML namespace as well as the @Transactional and @EnableTransactionManagement annotations.

There are three main properties that need 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 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 org.springframework.aop.interceptor.PerformanceMonitorInterceptor.

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>
Authors
Juergen Hoeller, Dmitriy Kopylenko, Rod Johnson, Chris Beams
Since
21.08.2003
See Also
setTransactionManager, setTarget, setTransactionAttributes, TransactionInterceptor, org.springframework.aop.framework.ProxyFactoryBean

Field Summary

Modifier and TypeField and Description
private Pointcut
private final TransactionInterceptor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Object
createMainInterceptor()

Implements abstract org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.createMainInterceptor.

Creates an advisor for this FactoryBean's TransactionInterceptor.

protected void
postProcessProxyFactory(ProxyFactory
the AOP ProxyFactory about to be used
proxyFactory
)

Overrides org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.postProcessProxyFactory.

As of 4.2, this method adds TransactionalProxy to the set of proxy interfaces in order to avoid re-processing of transaction metadata.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

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.

public void
setPointcut(Pointcut pointcut)

Set a pointcut, i.e a bean that can cause conditional invocation of the TransactionInterceptor depending on method and attributes passed.

public void
setTransactionAttributes(Properties transactionAttributes)

Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly".

public void
setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)

Set the transaction attribute source which is used to find transaction attributes.

public void
setTransactionManager(PlatformTransactionManager transactionManager)

Set the default transaction manager.

Inherited from org.springframework.aop.framework.AbstractSingletonProxyFactoryBean:
afterPropertiesSetcreateTargetSourcegetObjectgetObjectTypeisSingletonsetAdvisorAdapterRegistrysetBeanClassLoadersetPostInterceptorssetPreInterceptorssetProxyClassLoadersetProxyInterfacessetTarget

Field Detail

pointcutback to summary
private Pointcut pointcut
Annotations
@Nullable
transactionInterceptorback to summary
private final TransactionInterceptor transactionInterceptor

Constructor Detail

TransactionProxyFactoryBeanback to summary
public TransactionProxyFactoryBean()

Method Detail

createMainInterceptorback to summary
protected Object createMainInterceptor()

Implements abstract org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.createMainInterceptor.

Creates an advisor for this FactoryBean's TransactionInterceptor.

Annotations
@Override
postProcessProxyFactoryback to summary
protected void postProcessProxyFactory(ProxyFactory proxyFactory)

Overrides org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.postProcessProxyFactory.

As of 4.2, this method adds TransactionalProxy to the set of proxy interfaces in order to avoid re-processing of transaction metadata.

Parameters
proxyFactory:ProxyFactory

Doc from org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.postProcessProxyFactory.

the AOP ProxyFactory about to be used

Annotations
@Override
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

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.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
See Also
org.springframework.beans.factory.BeanFactory#getBean(Class), org.springframework.transaction.PlatformTransactionManager
setPointcutback to summary
public void setPointcut(Pointcut pointcut)

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.

See Also
setPreInterceptors, setPostInterceptors
setTransactionAttributesback to summary
public void setTransactionAttributes(Properties transactionAttributes)

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.

See Also
setTransactionAttributeSource, TransactionInterceptor#setTransactionAttributes, TransactionAttributeEditor, NameMatchTransactionAttributeSource
setTransactionAttributeSourceback to summary
public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)

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.

See Also
setTransactionAttributes, TransactionInterceptor#setTransactionAttributeSource, TransactionAttributeSourceEditor, MethodMapTransactionAttributeSource, NameMatchTransactionAttributeSource, org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
setTransactionManagerback to summary
public void setTransactionManager(PlatformTransactionManager transactionManager)

Set the default transaction manager. This will perform actual transaction management: This class is just a way of invoking it.

See Also
TransactionInterceptor#setTransactionManager