首页 > 学院 > 开发设计 > 正文

TransactionProxyFactoryBean spring事务代理的工程bean API讲解/翻译

2019-11-06 08:43:29
字体:
来源:转载
供稿:网友

org.sPRingframework.transaction.interceptorClass TransactionProxyFactoryBean

java.lang.Object

  org.springframework.aop.framework.ProxyConfig

     org.springframework.aop.framework.AbstractSingletonProxyFactoryBean

         org.springframework.transaction.interceptor.TransactionProxyFactoryBean

All Implemented Interfaces:

Serializable, BeanClassLoaderAware,BeanFactoryAware, FactoryBean, InitializingBean

简化声明式事务处理的代理工厂bean。这是一个方便的选择与一个单独的一个标准的AOP ProxyFactoryBean TransactionInterceptor定义。这类的目的是覆盖声明性事务界定的典型案例:也就是说,包装单目标对象事务代理,代理目标实现的所有接口。有三个主要的属性,需要指定:

"transactionManager":使用PlatformTransactionManager的实现(例如,JtaTransactionManager实例)

"target":应该创建事务代理的目标对象

"transactionAttributes":事务属性(例如,传播行为和“readOnly”标记)每个目标方法名称(或方法名称模式)

如果“transactionManager”属性没有设置明确这FactoryBean运行在一个ListableBeanFactory,单个匹配类型的bean PlatformTransactionManager将从BeanFactory获取,TransactionInterceptor相比,事务属性指定为属性,方法名称作为键和transaction attribute描述符作为值。方法名称总是应用于目标类。

在内部,TransactionInterceptor实例使用,但是这类的用户不必关心,可选地,可以指定切入点的方法导致底层TransactionInterceptor条件调用,“preInterceptors”和“postInterceptors”属性可以设置为添加额外的拦截器,像PerformanceMonitorInterceptor或HibernateInterceptor / JdoInterceptor。

提示:这个类通常是使用父/子bean定义。通常,您将定义事务管理器和默认事务属性(方法名模式)在一个抽象父bean定义,派生具体的孩子bean定义为特定目标对象,这样把Bean的重复定义减少到最小。

<beanid="baseTransactionProxy"class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"

    abstract="true">

  <property name="transactionManager"ref="transactionManager"/>

  <property name="transactionAttributes">

    <props>

       <propkey="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>

 

方法Summary

protected  Object

createMainInterceptor()         为FactoryBean TransactionInterceptor创建一个通知.

 void

setBeanFactory(BeanFactory beanFactory)          这个回调是可选的:如果运行在BeanFactory没有显式设置,事务管理器一个匹配类型的bean PlatformTransactionManager将从BeanFactory获取。

 void

setPointcut(Pointcut pointcut)       设置一个切入点,我。e bean会导致条件TransactionInterceptor取决于方法的调用和属性。

 void

setTransactionAttributes(Properties transactionAttributes)         设置属性和方法名称作为键和事务属性描述符(解析通过TransactionAttributeEditor)值:例如键=“myMethod”,值=“传播必需的,只读的”。

 void

setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)         设置事务属性源用于找到事务属性.

 void

setTransactionManager(PlatformTransactionManager transactionManager)          设置事务管理器


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表