Class TransactionProxyFactoryBean
- java.lang.Object
- org.springframework.aop.framework.ProxyConfig
- org.springframework.aop.framework.AbstractSingletonProxyFactoryBean
- org.springframework.transaction.interceptor.TransactionProxyFactoryBean
 
 
 
- All Implemented Interfaces:
- Serializable,- Aware,- BeanClassLoaderAware,- BeanFactoryAware,- FactoryBean<Object>,- InitializingBean
 - public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean implements BeanFactoryAware Proxy factory bean for simplified declarative transaction handling. This is a convenient alternative to a standard AOP- ProxyFactoryBeanwith a separate- TransactionInterceptordefinition.- 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 the modern options for managing transactions in Spring applications. For these reasons, users should favor of the- tx:XML namespace as well as the @- Transactionaland @- EnableTransactionManagementannotations.- There are three main properties that need to be specified: - "transactionManager": the PlatformTransactionManagerimplementation to use (for example, aJtaTransactionManagerinstance)
- "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 - FactoryBeanis running in a- ListableBeanFactory, a single matching bean of type- PlatformTransactionManagerwill 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 - TransactionInterceptorinstance 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.- 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>- Since:
- 21.08.2003
- Author:
- Juergen Hoeller, Dmitriy Kopylenko, Rod Johnson, Chris Beams
- See Also:
- setTransactionManager(org.springframework.transaction.PlatformTransactionManager),- AbstractSingletonProxyFactoryBean.setTarget(java.lang.Object),- setTransactionAttributes(java.util.Properties),- TransactionInterceptor,- ProxyFactoryBean, Serialized Form
 
- Constructor Summary- Constructors - Constructor - Description - TransactionProxyFactoryBean()
 - Method Summary- All Methods Instance Methods Concrete Methods - Modifier and Type - Method - Description - protected Object- createMainInterceptor()Creates an advisor for this FactoryBean's TransactionInterceptor.- protected void- postProcessProxyFactory(ProxyFactory proxyFactory)As of 4.2, this method adds- TransactionalProxyto the set of proxy interfaces in order to avoid re-processing of transaction metadata.- void- setBeanFactory(BeanFactory beanFactory)This callback is optional: If running in a BeanFactory and no transaction manager has been set explicitly, a single matching bean of type- PlatformTransactionManagerwill be fetched from the BeanFactory.- 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.- void- setTransactionAttributes(Properties transactionAttributes)Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g.- void- setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)Set the transaction attribute source which is used to find transaction attributes.- void- setTransactionManager(PlatformTransactionManager transactionManager)Set the default transaction manager.- Methods inherited from class org.springframework.aop.framework.AbstractSingletonProxyFactoryBean- afterPropertiesSet, createTargetSource, getObject, getObjectType, isSingleton, setAdvisorAdapterRegistry, setBeanClassLoader, setPostInterceptors, setPreInterceptors, setProxyClassLoader, setProxyInterfaces, setTarget
 - Methods inherited from class org.springframework.aop.framework.ProxyConfig- copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
 
 
- Constructor Detail- TransactionProxyFactoryBean- public TransactionProxyFactoryBean() 
 
 - Method Detail- setTransactionManager- 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.
 - setTransactionAttributes- 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. 
 - setTransactionAttributeSource- 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(java.util.Properties),- TransactionAspectSupport.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource),- TransactionAttributeSourceEditor,- MethodMapTransactionAttributeSource,- NameMatchTransactionAttributeSource,- AnnotationTransactionAttributeSource
 
 - setPointcut- 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.
 - setBeanFactory- public void setBeanFactory(BeanFactory beanFactory) This callback is optional: If running in a BeanFactory and no transaction manager has been set explicitly, a single matching bean of type- PlatformTransactionManagerwill be fetched from the BeanFactory.- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- See Also:
- BeanFactory.getBean(Class),- PlatformTransactionManager
 
 - createMainInterceptor- protected Object createMainInterceptor() Creates an advisor for this FactoryBean's TransactionInterceptor.- Specified by:
- createMainInterceptorin class- AbstractSingletonProxyFactoryBean
 
 - postProcessProxyFactory- protected void postProcessProxyFactory(ProxyFactory proxyFactory) As of 4.2, this method adds- TransactionalProxyto the set of proxy interfaces in order to avoid re-processing of transaction metadata.- Overrides:
- postProcessProxyFactoryin class- AbstractSingletonProxyFactoryBean
- Parameters:
- proxyFactory- the AOP ProxyFactory about to be used