1

Tomcatのみを使用して、Java EE(JBossなどのアプリケーションサーバー)なしでSpringでグローバル(分散)トランザクションを実行しようとしています。関連する 2 つのデータベースがあり、1 つ目は PostgreSQL データベース、2 つ目は MS SQLServer データベースです。休止状態を使用せずにそれを行う方法はありますか?

私はatomikos APIで試しましたが、休止状態のセッションなしでそれを行う方法がわかりません. JDBC ベースまたは Spring に付属するその他のツールでそれを行うのは素晴らしいことだと思います。しかし、私はそれを行う方法がわかりません。

私のSpring構成は次のようになります:

<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- Get database driver XA properties from file -->
    <util:properties id="jdbcConfiguration1" location="classpath:jdbcconfiguration1.properties"/>
    <util:properties id="jdbcConfiguration2" location="classpath:jdbcconfiguration2.properties"/>

    <bean id="dataSourceA"
        class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
        <property name="uniqueResourceName"><value>XADBMS01</value></property>
        <property name="xaDataSourceClassName"><value>org.postgresql.xa.PGXADataSource</value></property>
        <property name="xaProperties" ref="jdbcConfiguration1"/>          
        <property name="poolSize"><value>1</value></property>
    </bean>

    <bean id="dataSourceB"
        class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">           
         ...
        <property name="poolSize"><value>1</value></property>
    </bean>    

    <!-- Construct Atomikos UserTransactionManager, needed to configure Spring -->
    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" 
          init-method="init" destroy-method="close">
        <!--  when close is called, should we force transactions to terminate or not? -->
        <property name="forceShutdown">
            <value>true</value>
        </property>
    </bean>

    <!-- Also use Atomikos UserTransactionImp, needed to configure Spring  --> 
    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
        <property name="transactionTimeout"><value>300</value></property>
    </bean>

    <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager"><ref bean="atomikosTransactionManager"  /></property>
    <property name="userTransaction"><ref bean="atomikosUserTransaction"  /></property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

   ......

</beans>

休止状態を使用する必要がありますか? 休止状態を使用したくないのは、私のニーズには複雑だと思うからです。その「Springベース」を行うことは可能ですか?

4

1 に答える 1

1

したがって、2 つの を構成しており、宣言DataSourceした方法と一致する方法で使用する方法を知りたいと考えています。JtaTransactionManager

Spring には 2 つのオプションがあります。

  • (推奨) を使用しJdbcTemplateます。の操作JdbcTemplateは、現在のトランザクションに自動的に参加します。

  • 現在のトランザクションを認識するDataSourceUitls.getConnection()を取得し、それに対して任意の JDBC 操作を実行するために使用します。Connection

どちらの場合も、 11. トランザクション管理で説明されているように、@Transactionalまたはを使用してコードでトランザクション境界を定義する必要があります。TransactionTemplate

于 2013-01-21T11:36:48.170 に答える