将JTA属性设置为Atomikos Spring Boot配置

我正在尝试使用以下命令在Spring Boot Configuration中设置Atomikos JTA属性(例如com.atomikos.icatch.max_timeout):

import com.atomikos.icatch.config.UserTransactionServiceImp;
import com.atomikos.icatch.jta.UserTransactionImp;
import com.atomikos.icatch.jta.UserTransactionManager;

import java.util.Properties;

import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.jta.JtaTransactionManager;

@Configuration
@EnableTransactionManagement
public class TransactionManagementConfiguration 
{

    @Bean(name="userTransactionServiceImp")
    public UserTransactionServiceImp userTransactionServiceImp()
    {
        Properties properties = new Properties();
        properties.setProperty("com.atomikos.icatch.max_timeout", "600000");
        UserTransactionServiceImp userTransactionServiceImp = new UserTransactionServiceImp(properties);
        return userTransactionServiceImp;
    }

    @Bean
    @DependsOn("userTransactionServiceImp")
    public UserTransaction userTransaction()
    {
        UserTransactionImp userTransactionImp = new UserTransactionImp();
        return userTransactionImp;
    }

    @Bean
    @DependsOn("userTransactionServiceImp")
    public TransactionManager userTransactionManager()
    {
        UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setStartupTransactionService(false);
        userTransactionManager.setForceShutdown(false);
        return userTransactionManager;
    }

    @Bean
    public PlatformTransactionManager transactionManager()
    {
        return new JtaTransactionManager(userTransaction(), userTransactionManager());
    }    

}

但是,未获取com.atomikos.icatch.max_timeout的属性设置更改.

2015-09-23 14:31:33.810  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING core version: 3.9.3
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.automatic_resource_registration = true
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.client_demarcation = false
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.threaded_2pc = false
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.serial_jta_transactions = true
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.serializable_logging = true
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.log_base_dir = .\
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.max_actives = 50
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.checkpoint_interval = 500
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.enable_logging = true
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.output_dir = .\
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.log_base_name = tmlog
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.max_timeout = 300000
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.tm_unique_name = 127.0.0.1.tm
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING java.naming.factory.initial = com.sun.jndi.rmi.registry.RegistryContextFactory
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING java.naming.provider.url = rmi://localhost:1099
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.force_shutdown_on_vm_exit = false
2015-09-23 14:31:33.811  INFO 4748 --- [nio-8080-exec-1] c.a.i.c.i.AbstractUserTransactionService : USING com.atomikos.icatch.default_jta_timeout = 10000

我已经阅读了有限的JTA Spring Boot资料(http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html),在Atomokis上搜索等等,但我没做错,我可能做错了什么.

一直使用以下Atomikos Spring JTA文档有一个Spring Boot配置代码指南:http://www.atomikos.com/Documentation/SpringIntegration#The_Advanced_Case_As_of_3_3

任何洞察这个问题将不胜感激.

编辑:更改@Bean initMethod / destroyMethod,并将@DependsOn添加到transactionManager()似乎修复了已发布的:

    @Bean(name="userTransactionServiceImp", initMethod = "init", destroyMethod = "shutdownForce")
    public UserTransactionServiceImp userTransactionServiceImp()
    {
        Properties properties = new Properties();
        properties.setProperty("com.atomikos.icatch.max_timeout", "3600000");
        UserTransactionServiceImp userTransactionServiceImp = new UserTransactionServiceImp(properties);
        return userTransactionServiceImp;
    }

    @Bean
    @DependsOn("userTransactionServiceImp")
    public UserTransaction userTransaction()
    {
        UserTransactionImp userTransactionImp = new UserTransactionImp();
        return userTransactionImp;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    @DependsOn("userTransactionServiceImp")
    public TransactionManager userTransactionManager()
    {
        UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setStartupTransactionService(false);
        userTransactionManager.setForceShutdown(false);
        return userTransactionManager;
    }

    @Bean
    @DependsOn("userTransactionServiceImp")
    public PlatformTransactionManager transactionManager()
    {
        return new JtaTransactionManager(userTransaction(), userTransactionManager());
    }

解决方法:

根据Atomikos docs,可以通过UserTransaction.setTransactionTimeout()配置属性com.atomikos.icatch.max_timeout.

这样的配置适合我(注意这个API在几秒钟内使用值):

  @Bean(initMethod = "init", destroyMethod = "close")
  public UserTransactionManager atomikosTransactionManager()
      throws SystemException {
    UserTransactionManager userTransactionManager =
        new UserTransactionManager();
    userTransactionManager.setTransactionTimeout(600);
    return userTransactionManager;
  }

  @Bean
  public JtaTransactionManager transactionManager(
      UserTransactionManager atomikosTransactionManager) {
    JtaTransactionManager transactionManager = new JtaTransactionManager();
    transactionManager.setTransactionManager(atomikosTransactionManager);
    transactionManager.setUserTransaction(atomikosTransactionManager);
    return transactionManager;
  }
上一篇:Tomcat 结合Atomikos 实现JTA


下一篇:com.atomikos.datasource.ResourceException: XA resource 'masterDB': resume for XID异常