Recently, the project switched the environment and replaced weblogic with tomcat. I recorded the problems encountered in the middle. Using JTA in Tomcat, you can deploy Atomikos in Tomcat and use the data source supported by Tomcat; you can also configure it in the project and use Spring to configure the data source, connection pool, transaction manager, etc. The two methods have their own characteristics. This article only introduces the integration of Tomcat and Atomikos. After the integration, Tomcat can provide JTA transaction manager and data source to the outside world. Before using Atomikos, we also used JOTM, but under high concurrency conditions, JOTM frequently failed and we had to give up. Through testing, we found that Atomikos had good performance and stability. We used the latest version 4.04 of Atomikos. The Jar package can be obtained from the Maven configuration library. The link address is: http://mvnrepository.com/artifact/com.atomikos If you do not use Hibernate, the required packages include: atomikos-util.jar, jta.jar, transactions.jar, transactions-api.jar, transactions-jdbc.jar, transactions-jta.jar Integration Package: atomikos-integration-extension-3.7.2.jar Remember to put the database driver Step 1: Copy these jars to the lib directory of tomcat. To integrate Tomcat with Atomikos, you also need an integration package. This integration package contains two classes. You can refer to the implementation yourself or use the official jar package. The latest one is atomikos-integration-extension-3.7.2.jar Step 2: Add a listener in tomcat/config/server.xml
Step 3: Add data sources and related transaction managers in tomcat/config/context.xml. The following is a reference example. Modify the parameters as appropriate. <Resource name="jdbc/DS_MYSQL" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean" uniqueResourceName="jdbc/DS_MYSQL" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.databaseName="db_test" xaProperties.serverName="localhost" xaProperties.port="3306" xaProperties.user="root" xaProperties.password="root" maxPoolSize="200" xaProperties.url="jdbc:mysql://localhost:3306/db_test?characterEncoding=UTF8" factory="com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory" /> <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" /> <Transaction factory="com.atomikos.icatch.jta.UserTransactionFactory" /> Step 4: Add a jta.properties file in the tomcat/lib directory and set the Atomikos transaction-related parameters. Otherwise, the default configuration parameters will be used. Some concurrent transaction numbers (50 by default) and timeouts need to be adjusted. Some parameter configurations in the file are given below. For parameter explanations, please refer to the official documentation: https://www.atomikos.com/Documentation/JtaProperties Add this line configuration com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory The default values of the parameters in Atomikos are defined in transactions.jar, transactions-default.properties: if you are interested, you can go and see it yourself After configuring the above four steps, the integration of Tomcat is complete. Spring can be used in the project to associate the data source and transaction manager. The reference configuration is as follows: <!-- JNDI template configuration information, used to connect to the application server --> <bean class="org.springframework.jndi.JndiTemplate" id="jndiTemplate" /> <bean class="org.springframework.jndi.JndiObjectFactoryBean" id="dataSource"> <property name="jndiName"> <value>java:comp/env/jdbc/DS_MYSQL</value> </property> <property name="jndiTemplate"> <ref bean="jndiTemplate"/> </property> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <!--User transaction object--> <bean class="org.springframework.jndi.JndiObjectFactoryBean" id="userTransaction"> <!--class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">--> <property name="jndiName"> <value>java:comp/UserTransaction</value> </property> <property name="jndiTemplate"> <ref bean="jndiTemplate"/> </property> </bean> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="false" /> </bean> <!-- Configure annotation-based declarative transaction manager --> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction" ref="userTransaction" /> <property name="transactionManager" ref="atomikosTransactionManager" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> The following is the configuration used in my project: It is recommended to configure in conf.xml
auth="Container" type="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" uniqueResourceName="jdbc/DS_MYSQL" driverClassName="com.mysql.jdbc.Driver" maxPoolSize="200" url="jdbc:mysql://localhost:3306/db_test?characterEncoding=UTF8" user="root" password="root" factory="com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory" /> **Pitfall Record** **Here, because there is a transaction manager TransactionManager, UserTransaction cannot be obtained through this type. After debugging, it is found that this class is not found** **Change to type="com.atomikos.icatch.jta.userTransactionImp" to successfully obtain UserTransaction,** <Resource name="UserTransaction" auth="Container" type="com.atomikos.icatch.jta.userTransactionImp"/> <Transaction factory="com.atomikos.icatch.jta.UserTransactionFactory" /> https://blog.csdn.net/xuyu_yt/article/details/77905553?locationNum=14%20fps=1 This is the end of this article about Tomcat combined with Atomikos to implement JTA. For more relevant content about Atomikos implementing JTA, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Solve the problem of MySql8.0 checking transaction isolation level error
>>: Detailed explanation of the use of CSS3 rgb and rgba (transparent color)
Summarize This article ends here. I hope it can b...
Copy code The code is as follows: <html> &l...
1. In the control panel, uninstall all components...
The operating system for the following content is...
Although I have run some projects in Docker envir...
Use self:: or __CLASS__ to get a static reference...
First time using docker to package and deploy ima...
MySQL executes SQL through the process of SQL par...
Table of contents Preface 1.v-show 2.v-if 3. The ...
First, let’s look at the GIF operation: Case 1: S...
Preface NAT forwarding: Simply put, NAT is the us...
How to define and use: Use the slot tag definitio...
First of all, you need to understand why you use ...
Related Documents Part of this article is referen...
This article example shares the specific code for...