ステップ構成の制御ばね宣言的トランザクションベースのXML

1.設定トランザクションマネージャ

<!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

2. [設定トランザクションの通知

  • 私たちは、トランザクションをインポートする必要があり、この時点での制約:. TX名前と空間の制約はなく、必要性のAOP
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd">
</beans>
  • 。使用B TX:取引通知設定するためのアドバイス]タブ
    のプロパティを:
    id:トランザクション通知に固有の識別から。
    transaction-manager:トランザクションマネージャの参照を提供するために、トランザクション通知。
<!--配置事务的通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager"></tx:advice>

共通の構成3. AOPポイントカット式

<!--配置AOP-->
    <aop:config>
        <!--配置切入点表达式-->
        <aop:pointcut id="pt01" expression="execution(* net.togogo.service.impl.*.*(..))"/>
    </aop:config>

トランザクションおよび出発点通知表現の間の対応関係を確立4.

<!--配置AOP-->
    <aop:config>
        <!--配置切入点表达式-->
        <aop:pointcut id="pt01" expression="execution(* net.togogo.service.impl.*.*(..))"/>
        <!--建立切入点表达式和事务通知的对应关系-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pt01"></aop:advisor>
    </aop:config>

設定可能なトランザクション・プロパティ:

  • これは、トランザクションにTX通知することである:内部アドバイスラベル
    isolation:トランザクション分離レベルを指定するために使用します。デフォルト値は、デフォルトでデータベースを使用するデフォルトの分離レベルを表します。

    propagation:トランザクション伝播の振る舞いを指定するために使用します。デフォルトは要求され、それは選択にトランザクション、追加および削除があることを示します。Queryメソッドをサポートを選択することができます。

    read-only:トランザクションが読み取り専用であるかどうかを指定するために使用します。唯一のクエリメソッドをtrueに設定することができ、デフォルト値はfalse、読み取りおよび書き込みです。

    timeout:指定されたトランザクションのタイムアウト。デフォルト値は-1、決して時間を意味しています。秒に設定された値、もし。

    rollback-for:例外が発生したときに指定した例外、トランザクションはロールバックされます。その他の異常を生成する場合、トランザクションはロールバックされていません。デフォルト値はありません。異常がロールバックされ示しています。
    no-rollback-for:異常が発生した場合、異常を指定するために使用される場合、トランザクションがロールバックされていない、他の異常、トランザクションのロールバックを生成します。デフォルト値は、任意の異常がロールバックされる示し、ありません。

<!--配置事务的通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--配置事务的属性-->
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" read-only="false"/>
            <tx:method name="find" propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>
    </tx:advice>
公開された31元の記事 ウォンの賞賛1 ビュー249

おすすめ

転載: blog.csdn.net/weixin_41605945/article/details/104511186