gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:42:28 24 4
gpt4 key购买 nike

我正在尝试使用以下方法在 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 Spring Boot Material ( 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 , 属性(property) 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;
}

关于spring - 将 JTA 属性设置为 Atomikos + Spring Boot 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32747101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com