JTA can use a transaction on multiple databases, WebLogic and other application servers provide JTA data source support, can be used directly. But Tomcat itself does not support this feature. If you want to use JTA on Tomcat, you must use a different tool. JOTM is a standalone component that can provide JTA functionality.
<?xml version= "1.0" encoding= "UTF-8"? > <beans xmlns= "http// Www.springframework.org/schema/beans " xmlns:xsi=" http// Www.w3.org/2001/XMLSchema-instance " xmlns:context=" http// Www.springframework.org/schema/context " xmlns:aop=" http// WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP " xmlns:tx=" http// Www.springframework.org/schema/tx " xsi:schemalocation=" http// Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http:// www.springframework.org/schema/context/spring-context-2.5.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http:// Www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd "> <description>springJTA</description> <!--Specify the properties file used in the spring configuration <bean id= "Propertyconfig" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= "Locations" > <list> <value>classpath:jdbc.properties</value> </list> </ property> </bean> --> <!-- jotm Instances --> <bean id= "Jotm" class= "Org.springframework.transaction.jta.JotmFactoryBean" > <property name= "DefaultTimeout " value=" 500000 "/> </bean> <!--&NBSP;JTA transaction manager --> <bean id= " Jtatransactionmanager " class=" Org.springframework.transaction.jta.JtaTransactionManager "> &Nbsp; <property name= "UserTransaction" ref= "Jotm" / > </bean> <!-- Data source a --> <bean Id= "Datasourcea" class= "Org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method= "Shutdown" > <property name= "DataSource" > <bean class= "Org.enhydra.jdbc.standard.StandardXADataSource" destroy-method= "Shutdown" > <property Name= "TransactionManager" ref= "Jotm"/> &nbSp; <property name= "drivername" value= "Com.mysql.jdbc.Driver"/> <property name= "url" value= "Jdbc:mysql://localhost:3306/emp_mvc"/> </bean> </property> <property name= "User" value= "root"/> <property name= "Password" value= "123456"/> </bean> <!-- Data source b --> <bean id= "DataSourceB" class= " Org.enhydra.jdbc.pool.StandardXAPOoldatasource " destroy-method=" Shutdown "> <property name= "DataSource" > <bean class= "Org.enhydra.jdbc.standard.StandardXADataSource" destroy-method= "Shutdown" > <property name= "TransactionManager" ref= "Jotm"/> <property name= "drivername" value= "Com.mysql.jdbc.Driver"/> <property name= " URL " value=" JDBC:MYSQL://LOCALHOST:3306/EMP_MVC2 "/> </bean> </property> <property name= "User" value= "root"/> <property name= "Password" value = "123456"/> </bean> <bean id = "Sessionfactorya" class= " Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean "> <property name = "DataSource" ref= "Datasourcea"/> <property name= "Mappingresources" > <list> <value>com/ouku/JOTM/entity/Emp.hbm.xml</value> </list> </property> </bean> <bean id = "Sessionfactoryb" class= " Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean "> <property name = "DataSource" ref= " Datasourceb "/> <property name=" Mappingresources "> <list> <value>com/ouku/jotm /entity/emp2.hbm.xml</value> </list> </property> </bean> <!-- Transaction facets configuration --> <aop:config> <aop:pointcut id= "Pointcut" expression= "Execution (*&NBSP;COM.OUKU.JOTM. *.*(..))" />< all methods under!-- Package and its sub-packages &NBSP;-->&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; <aop:advisor pointcut-ref= "Pointcut" advice-ref= "Txadvice"/> <aop:advisor pointcut= "Execution (* *. Ouku. Jotm.*.* (..)) " advice-ref= "Txadvice"/> </aop:config> <!-- Notification configuration --> <tx:advice id= "Txadvice" transaction-manager= "Jtatransactionmanager" > <tx:attributes> <tx:method name= "delete*" rollback-for= " Exception "/>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;<TX: Method name= "save*" rollback-for= "Exception"/>&nbSp; <tx:method name= " update* " rollback-for=" Exception "/> <tx:method name= "find*" read-only= "true" rollback-for= "Exception"/> <tx:method name= "*" Read-only= "true" rollback-for= "Exception"/> </tx:attributes> </tx:advice> <bean id= "Genericdao" class= " Com.ouku.JOTM.DAO.GenericDaoImpl " autowire=" ByName "> <property name= "Sessionfactorya" ref=" ></property> "Sessionfactorya" <property name= "Sessionfactoryb" ref= "Sessionfactoryb" ></property> </bean> <bean id= " UserService " class= "Com.ouku.JOTM.biz.UserServiceImpl" autowire= "ByName" > </ Bean> </beans>
This article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1744796
Spring JTA Transaction Configuration Jotm