public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean implements BeanFactoryAware
TransactionInterceptor 定義を持つ標準 AOP ProxyFactoryBean の便利な代替手段です。HISTORICAL NOTE : このクラスはもともと、宣言的なトランザクション境界の典型的なケースをカバーするために設計されました: つまり、シングルトンターゲットオブジェクトをトランザクションプロキシでラップし、ターゲットが実装するすべてのインターフェースをプロキシします。ただし、Spring バージョン 2.0 以降では、ここで提供される機能は、より便利な tx: XML 名前空間に置き換えられています。Spring アプリケーションでトランザクションを管理するための最新のオプションを理解するには、Spring リファレンスドキュメントの宣言型トランザクション管理のセクションを参照してください。これらの理由により、ユーザーは、@ Transactional と同様に tx: XML 名前空間を優先する必要があります。および @EnableTransactionManagement アノテーション。
指定する必要がある主なプロパティは 3 つあります。
PlatformTransactionManager 実装 (たとえば、JtaTransactionManager インスタンス) "transactionManager" プロパティが明示的に設定されておらず、この FactoryBean が ListableBeanFactory で実行されている場合、型 PlatformTransactionManager の一致する単一の Bean が BeanFactory から取得されます。
TransactionInterceptor とは対照的に、トランザクション属性はプロパティとして指定され、メソッド名はキー、トランザクション属性記述子は値として指定されます。メソッド名は常にターゲットクラスに適用されます。
内部的には TransactionInterceptor インスタンスが使用されますが、このクラスのユーザーは気にする必要はありません。オプションで、メソッド pointcut を指定して、基になる TransactionInterceptor を条件付きで呼び出すことができます。
"preInterceptors" および "postInterceptors" プロパティを設定すると、PerformanceMonitorInterceptor などの追加のインターセプターをミックスに追加できます。
ヒント : このクラスは、親 / 子 Bean 定義でよく使用されます。通常、トランザクションマネージャーとデフォルトのトランザクション属性(メソッド名パターン用)を抽象親 Bean 定義で定義し、特定のターゲットオブジェクトの具体的な子 Bean 定義を派生させます。これにより、Bean ごとの定義作業が最小限に抑えられます。
<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>setTransactionManager(org.springframework.transaction.PlatformTransactionManager), AbstractSingletonProxyFactoryBean.setTarget(java.lang.Object), setTransactionAttributes(java.util.Properties), TransactionInterceptor, ProxyFactoryBean, 連載形式 OBJECT_TYPE_ATTRIBUTE| コンストラクターと説明 |
|---|
TransactionProxyFactoryBean() |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected ObjectSE | createMainInterceptor() この FactoryBean の TransactionInterceptor のアドバイザを作成します。 |
protected void | postProcessProxyFactory(ProxyFactory proxyFactory)4.2 以降、このメソッドは、トランザクションメタデータの再処理を回避するために、プロキシインターフェースのセットに TransactionalProxy を追加します。 |
void | setBeanFactory(BeanFactory beanFactory) このコールバックはオプションです: BeanFactory で実行していて、トランザクションマネージャーが明示的に設定されていない場合、BeanFactory から PlatformTransactionManager 型の一致する単一の Bean がフェッチされます。 |
void | setPointcut(Pointcut pointcut) 渡されたメソッドと属性に応じて、TransactionInterceptor の条件付き呼び出しを引き起こす可能性があるポイントカット、つまり Bean を設定します。 |
void | setTransactionAttributes(PropertiesSE transactionAttributes) メソッド名をキーとして、トランザクション属性記述子(TransactionAttributeEditor を介して解析)を値としてプロパティを設定します。 |
void | setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。 |
void | setTransactionManager(PlatformTransactionManager transactionManager) デフォルトのトランザクションマネージャーを設定します。 |
afterPropertiesSet, createTargetSource, getObject, getObjectType, isSingleton, setAdvisorAdapterRegistry, setBeanClassLoader, setPostInterceptors, setPreInterceptors, setProxyClassLoader, setProxyInterfaces, setTargetcopyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toStringcloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSEpublic void setTransactionManager(PlatformTransactionManager transactionManager)
public void setTransactionAttributes(PropertiesSE transactionAttributes)
メモ: メソッド名は、インターフェースで定義されているか、クラス自体で定義されているかに関係なく、常にターゲットクラスに適用されます。
内部的には、NameMatchTransactionAttributeSource は指定されたプロパティから作成されます。
public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
setTransactionAttributes(java.util.Properties), TransactionAspectSupport.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource), TransactionAttributeSourceEditor, MethodMapTransactionAttributeSource, NameMatchTransactionAttributeSource, AnnotationTransactionAttributeSourcepublic void setPointcut(Pointcut pointcut)
public void setBeanFactory(BeanFactory beanFactory)
PlatformTransactionManager 型の一致する単一の Bean がフェッチされます。BeanFactoryAware の setBeanFactory beanFactory - 所有 BeanFactory(非 null)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。BeanFactory.getBean(Class), PlatformTransactionManagerprotected ObjectSE createMainInterceptor()
protected void postProcessProxyFactory(ProxyFactory proxyFactory)
TransactionalProxy を追加します。AbstractSingletonProxyFactoryBean の postProcessProxyFactory proxyFactory - 使用される AOP ProxyFactory