ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 软件工程 >> SpringMVC+MyBatis+JMS+JTA(分布式事务)

SpringMVC+MyBatis+JMS+JTA(分布式事务)(1/3)

来源:网络整理     时间:2015-12-17     关键词:队列,Spring,连接数据库,Annotation,JDBC

本篇文章主要介绍了"SpringMVC+MyBatis+JMS+JTA(分布式事务)",主要涉及到队列,Spring,连接数据库,Annotation,JDBC方面的内容,对于软件工程感兴趣的同学可以参考一下: SpringMVC+MyBatis 相信已经是现在企业开发中常用技术了。 因为一些需求,我们需要集成JMS(我使用的是ActiveMQ),大家应该都知道,MQ...

SpringMVC+MyBatis 相信已经是现在企业开发中常用技术了。
因为一些需求,我们需要集成JMS(我使用的是ActiveMQ),大家应该都知道,MQ也可以认为是一个数据源,数据也是数据源。这种情况下,如果我们在一个方法内操作JMS和数据库,我们就需要保证这个方法执行需要满足原子性。
这也就意味这一个问题,我们要多个数据源在同一个事务中。这里不枚举市面上的所有解决方案,其实atomikos JTA 是一个比较不错分布式事务管理器。
当然如果没有使用到JMS,在需要多数据源(也就是需要连接多个数据库)的情况同样适用。

下面将项目的主要配置贴出来共享:
1、applicationContext.xml

<beansxmlns="http://www.Springframework.org/schema/beans"xmlns:context="http://www.Springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:amq="http://activemq.apache.org/schema/core"xsi:schemaLocation="http://www.Springframework.org/schema/beans   
        http://www.Springframework.org/schema/beans/Spring-beans-4.1.xsd   
        http://www.Springframework.org/schema/context   
        http://www.Springframework.org/schema/context/Spring-context-4.1.xsd
        http://activemq.apache.org/schema/core
        http://activemq.apache.org/schema/core/activemq-core-5.13.0.xsd"><beanclass="org.Springframework.beans.factory.Annotation.AutowiredAnnotationBeanPostProcessor"/><context:component-scanbase-package="com.hvgroup.zhuhai10086.jms"><context:exclude-filtertype="Annotation"expression="org.Springframework.stereotype.Controller"/>context:component-scan><beanclass="org.Springframework.beans.factory.config.PropertyPlaceholderConfigurer"><propertyname="locations"><list><value>classpath:config/config.propertiesvalue>list>property>bean><importresource="classpath:Spring/applicationContext-Service.xml" />beans>

2、applicationContext-Service.xml

<beansxmlns="http://www.Springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jee="http://www.Springframework.org/schema/jee"xmlns:mvc="http://www.Springframework.org/schema/mvc"xmlns:tx="http://www.Springframework.org/schema/tx"xmlns:context="http://www.Springframework.org/schema/context"xsi:schemaLocation="http://www.Springframework.org/schema/jee http://www.Springframework.org/schema/jee/Spring-jee-4.1.xsd
        http://www.Springframework.org/schema/mvc http://www.Springframework.org/schema/mvc/Spring-mvc-4.1.xsd
        http://www.Springframework.org/schema/beans http://www.Springframework.org/schema/beans/Spring-beans-4.1.xsd
        http://www.Springframework.org/schema/context http://www.Springframework.org/schema/context/Spring-context-4.1.xsd
        http://www.Springframework.org/schema/tx http://www.Springframework.org/schema/tx/Spring-tx-4.1.xsd"> --><beanid="dataSource"class="com.atomikos.JDBC.AtomikosDataSourceBean"init-method="init"destroy-method="close"><propertyname="uniqueResourceName"value="ds1" /><propertyname="xaDataSourceClassName"value="com.mysql.JDBC.JDBC2.optional.MysqlXADataSource" /><propertyname="xaProperties"><props><propkey="URL">${JDBC.url}prop><propkey="user">${JDBC.username}prop><propkey="password">${JDBC.password}prop>props>property><propertyname="minPoolSize"value="5" /><propertyname="maxPoolSize"value="20" /><propertyname="maxIdleTime"value="60" /><propertyname="testQuery"><value>select 1value>property>bean><beanid="sqlSessionFactory"class="org.mybatis.Spring.SqlSessionFactoryBean"><propertyname="dataSource"ref="dataSource" /><propertyname="mapperLocations"><list><value>classpath*:com/hvgroup/zhuhai10086/jms/**/sql/mysql/*Mapper.xml
                value>list>property><propertyname="plugins"><array><beanclass="com.github.pagehelper.PageHelper"><propertyname="properties"><value>
                            offsetAsPageNum=true
                            rowBoundsWithCount=true
                            reas
                        value>property>bean>array>property>bean><beanclass="org.mybatis.Spring.mapper.MapperScannerConfigurer"><propertyname="basePackage"value="com.hvgroup.zhuhai10086.jms.**.mapper" /><propertyname="markerInterface"value="com.hvgroup.zhuhai10086.jms.mapper.SqlMapper" /><propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory" />bean><beanid="userTransactionService"class="com.atomikos.icatch.config.UserTransactionServiceImp"init-method="init"destroy-method="shutdownForce"><constructor-arg><props><propkey="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactoryprop>props>constructor-arg>bean><beanid="atomikosTransactionManager"class="com.atomikos.icatch.jta.UserTransactionManager"depends-on="userTransactionService"init-method="init"destroy-method="close" ><propertyname="forceShutdown"value="false"/>bean><beanid="atomikosUserTransaction"class="com.atomikos.icatch.jta.UserTransactionImp" ><propertyname="transactionTimeout"value="300"/>bean><beanid="jtaTransactionManager"class="org.Springframework.transaction.jta.JtaTransactionManager"><propertyname="transactionManager"ref="atomikosTransactionManager"/><propertyname="userTransaction"ref="atomikosUserTransaction"/>bean><tx:Annotation-driventransaction-manager="jtaTransactionManager" />beans>

3、ActiveMQ-XA.xml

相关图片

相关文章