java 使用 Atomikos 在 Tomcat 服务器中正确设置 JTA 事务管理器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15637921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:21:29  来源:igfitidea点击:

Correctly setting up JTA Transaction Manager in Tomcat Server with Atomikos

javaspringapache-camelspring-transactions

提问by Himanshu Yadav

How would I setup container-managed datasources and embedded Active MQ resources to JTATransactionManagerfor global Transactions?

我将如何JTATransactionManager为全局事务设置容器管理的数据源和嵌入式 Active MQ 资源?

I am using Tomcat 6 and installed Atomikos in it to support JTA. I use Hibernate for ORM. Here is my configuration:

我正在使用 Tomcat 6 并在其中安装了 Atomikos 以支持 JTA。我将 Hibernate 用于 ORM。这是我的配置:

<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="false" /> 
</bean> 

<bean id="AtomikosUserTransaction"  
   class="com.atomikos.icatch.jta.UserTransactionImp">      
   <property name="transactionTimeout" value="300" /> 
</bean>

<jee:jndi-lookup expected-type="javax.sql.DataSource" id="dataSource" jndi-name="jdbc/EDITSOLUTIONS"/>

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingResources"/>
    <list>
        <value>../../src/editsolutions.hibernate.cfg.xml</value>
    </list>
    <property name="hibernateProperties">
        <value>
            hibernate.dialect=${hibernate.dialect}
        </value>
    </property>
</bean>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="failover://tcp://localhost:61616"/>
        </bean>
    </property>
</bean>

<bean id="jmsConnectionFactory"class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="failover://tcp://localhost:61616"/>
</bean>

<bean name="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="AtomikosTransactionManager" /> 
    <property name="userTransaction" ref="AtomikosUserTransaction" />
</bean>

Spring documentation says that JTA Transaction Manager need not be told about resources. That's what I have done.

Spring 文档说 JTA 事务管理器不需要被告知资源。这就是我所做的。



I have the following outstanding questions:

我有以下悬而未决的问题:

  1. I am not sure whether Atomikosis integrated properly or not?
  2. Is it OK to get the datasource from <jee:jndi-lookup>?
  3. Is Hiberante configuration correct with respect to JTATransactionManager?
  4. As it is embedded in JVM not managed by container, would JTATransactionManager be able to recognize ActimeMQ ?
  1. 我不确定是否Atomikos正确集成?
  2. 可以从 获取数据源<jee:jndi-lookup>吗?
  3. Hiberante 配置是否正确JTATransactionManager
  4. 由于它嵌入在不受容器管理的 JVM 中,因此 JTATransactionManager 能够识别 ActimeMQ 吗?

采纳答案by betelgeuse

Try with this very useful link: http://www.atomikos.com/Documentation/SpringIntegration

试试这个非常有用的链接:http: //www.atomikos.com/Documentation/SpringIntegration

Remember to configure the datasource in this way:

请记住以这种方式配置数据源:

<bean id="dataSourceA" class="com.atomikos.jdbc.AtomikosDataSourceBean"  init-method="init" destroy-method="close">
    <qualifier value="jmsRecoveryDatabaseSchema"/> 
    <property name="uniqueResourceName"><value>XADS1</value></property> 
    <property name="xaDataSourceClassName"> 
        <value>oracle.jdbc.xa.client.OracleXADataSource</value> 
    </property> 
    <property name="xaProperties"> 
        <props> 
            <prop key="URL">${jdbc.url}</prop> 
            <prop key="user">${jdbc.username}</prop> 
           <prop key="password">${jdbc.password}</prop> 
        </props> 
    </property> 
    <property name="poolSize"><value>1</value></property>
    <property name="testQuery" value="SELECT 1 FROM DUAL"/>
</bean>

I hope it helps!

我希望它有帮助!