spring 将JTA属性设置为Atomikos + Sping Boot 配置

ltskdhd1  于 2022-10-30  发布在  Spring
关注(0)|答案(2)|浏览(237)

我尝试在Spring Boot配置中设置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 Sping Boot 材料(http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html),在Atomokis上搜索,等等,但没有运气知道我可能做错了什么。
已经使用过的以下Atomikos Spring JTA文档中有一个关于Sping 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());
    }
dgsult0t

dgsult0t1#

根据Atomikos文档,属性com.atomikos.icatch.max_timeout也可以通过UserTransaction.setTransactionTimeout()进行配置。
这样的配置对我很有效(请注意,此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;
  }
x6492ojm

x6492ojm2#

@Configuration 公共类AtomikosJtaConfiguration {

@Bean
public UserTransaction userTransaction() throws SystemException {
    UserTransactionImp userTransactionImp= new UserTransactionImp();
    userTransactionImp.setTransactionTimeout(1000);
    return userTransactionImp;
}

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

}

相关问题