现在的位置: 首页 > 综合 > 正文

org.springframework.transaction.interceptor 类 TransactionProxyFactoryBean

2019年05月12日 ⁄ 综合 ⁄ 共 4467字 ⁄ 字号 评论关闭

转载自:这里

org.springframework.transaction.interceptor
类 TransactionProxyFactoryBean

java.lang.Object
  继承者 org.springframework.aop.framework.ProxyConfig
      继承者 org.springframework.aop.framework.AbstractSingletonProxyFactoryBean
          继承者 org.springframework.transaction.interceptor.TransactionProxyFactoryBean
所有已实现的接口:
java.io.Serializable,
BeanClassLoaderAware
,
BeanFactoryAware
,
FactoryBean
,
InitializingBean

public class TransactionProxyFactoryBean
extends AbstractSingletonProxyFactoryBean
implements FactoryBean, BeanFactoryAware

声明式事务代理简化处理工厂bean。这是一个方便的替代标准的AOP的
ProxyFactoryBean
一个单独的
TransactionInterceptor
定义。

这个类是为了支付交易划分典型案件的声明,即:包装用一个单身事务代理的目标对象,代理所有的接口,这个目标实现了。

有三个需要指定主要性能:

  • “transactionManager”的:该PlatformTransactionManager实施使用(例如,一个

    JtaTransactionManager
    实例)
  • “目标”:目标对象应该是一个事务代理创建
  • “transactionAttributes”:交易属性(例如,传播行为和“只读”标志)每个目标方法名(或方法名模式)

如果“transactionManager”的属性没有明确设置这种FactoryBean运行在一个

ListableBeanFactory
,一个匹配豆型PlatformTransactionManager将获取的

BeanFactory

与此相反的TransactionInterceptor 的事务属性被指定为属性,以作为值作为键和事务属性描述方法名。方法的名字总是应用到目标类。

在内部,一个TransactionInterceptor 实例被使用,但这一类的用户并没有在意。或者,一个方法切入点可以指定会导致基础条件援引TransactionInterceptor

在“preInterceptors”和“postInterceptors”属性可以设置为添加额外的拦截器的组合,如
PerformanceMonitorInterceptor

HibernateInterceptor
/
JdoInterceptor

提示:这个类是经常使用父/子bean定义。通常,您将定义一个抽象的交易经理父bean定义和默认的事务属性(方法名模式), 产生具体的儿童为特定目标对象的bean定义。这将减少到最低限度每bean定义的努力。

 <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <属性name="transactionManager" ref="transactionManager"/> <属性name="transactionAttributes"> <道具> <prop key="insert
 "> PROPAGATION_REQUIRED </道具> <prop key="update
 "> PROPAGATION_REQUIRED </道具> <prop key="
 "> PROPAGATION_REQUIRED,只读</道具> </道具> </物业> </豆> <bean id="myProxy" parent="baseTransactionProxy"> <属性name="target" ref="myTarget"/> </豆> <bean id="yourProxy" parent="baseTransactionProxy"> <属性name="target" ref="yourTarget"/> </豆>
 

英文注释

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:

  • "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 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>
 

从以下版本开始:
21.08.2003
作者:
Juergen Hoeller, Dmitriy Kopylenko, Rod Johnson
另请参见:
setTransactionManager(org.springframework.transaction.PlatformTransactionManager),

AbstractSingletonProxyFactoryBean.setTarget(java.lang.Object)
,
setTransactionAttributes(java.util.Properties)
,
TransactionInterceptor
,
ProxyFactoryBean
,
序列化表格

抱歉!评论已关闭.