将 JTA 属性设置为 Atomikos + Spring Boot 配置
Posted
技术标签:
【中文标题】将 JTA 属性设置为 Atomikos + Spring Boot 配置【英文标题】:Setting JTA Properties to an Atomikos + Spring Boot Configuration 【发布时间】:2015-12-21 05:10:23 【问题描述】:我正在尝试使用以下方法在 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 材料 (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());
【问题讨论】:
【参考方案1】:根据Atomikos docs,属性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;
【讨论】:
感谢您提供的信息,但更改对我不起作用。我对引用的 Atomikos 文档的解释是,UserTransaction.setTransactionTimeout() 受 com.atomikos.icatch.max_timeout 的最大值限制,这是我所看到的(即它不是设置 max_timeout 的替代方法)。跨度> @luboskrnac 你有什么解决方案吗?使用 userTransactionManager.setTransactionTimeout(600) 对我也不起作用......我在 *** 上发布了一个问题:***.com/questions/45282120/…以上是关于将 JTA 属性设置为 Atomikos + Spring Boot 配置的主要内容,如果未能解决你的问题,请参考以下文章
spring+mybatis+Atomikos JTA事务配置说明
spring3.0+Atomikos 构建jta的分布式事务