springmvc+mybatis下基于注解的Atomikos分布式事务配置

一、首先下载配置atomikos所需jar包,并将其添加至项目中:jar包下载

二、配置atomikos的初始化配置文件transactions.properties,添加至项目的classpath目录下,不进行配置则会引用默认值:

com.atomikos.icatch.console_file_name = xam.out
com.atomikos.icatch.log_base_name = xamlog.log
com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory
三、配置springmvc的config文件,与atomikos进行整合:

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
    http://www.springframework.org/schema/mvc   
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx    
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 	">
	<!-- 启用注解 -->
	<context:annotation-config />
	<!-- 启用spring注解扫描并指定包所在的位置 -->
	<context:component-scan base-package="com.fujfu.*" />
	<!-- 设置了此bean可以以${XXX}的方式读取mysql.properties
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:config/mysql.properties</value>
		</property>
	</bean> -->
	<!-- 富宝袋jdbc dataSource -->
	 <bean id="fujfuDataSource" class="com.alibaba.druid.pool.xa.DruidXADataSource" init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="jdbc:mysql://10.128.199.232:3306/fujfu?useUnicode=true&characterEncoding=UTF-8"/>
        <property name="username" value="furonge" />
        <property name="password" value="12345678" />
        <!-- 配置初始化大小、最小、最大  -->
        <property name="initialSize" value="0" />
        <property name="minIdle" value="1" />
        <property name="maxIdle" value="20" />
        <property name="maxActive" value="20" />
        <!-- 配置获取连接等待超时的时间  -->
        <property name="maxWait" value="60000"/>
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="60000" />
        <property name="validationQuery" value="SELECT 1" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="1800" />
        <property name="logAbandoned" value="true" />
        <property name="filters" value="mergeStat" />
    	</bean>
	<!-- account jdbc dataSource -->
	<bean id="accountDataSource" class="com.alibaba.druid.pool.xa.DruidXADataSource" init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="jdbc:mysql://10.128.199.232:3306/account?useUnicode=true&characterEncoding=UTF-8" />
        <property name="username" value="furonge" />
        <property name="password" value="12345678" />
        <!-- 配置初始化大小、最小、最大  -->
        <property name="initialSize" value="0" />
        <property name="minIdle" value="1" />
        <property name="maxIdle" value="20" />
        <property name="maxActive" value="20" />
        <!-- 配置获取连接等待超时的时间  -->
        <property name="maxWait" value="60000"/>
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="60000" />
        <property name="validationQuery" value="SELECT 1" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="1800" />
        <property name="logAbandoned" value="true" />
        <property name="filters" value="mergeStat" />
    	</bean> 
	<!-- sqlSessionFactory配置 -->
	<bean id="fuyhuiSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="fujfuDataSource" />
		<!-- 自动扫描mapping.xml文件 -->
		<property name="mapperLocations">
			<array>
				<value>classpath*:com/fujfu/dao/*/mapping/*.xml</value>
				<value>classpath*:com/fujfu/dao/app/fkd/*/mapping/*.xml</value>
				<value>classpath*:com/fujfu/dao/app/version/mapping/*.xml</value>
			</array>
		</property>
	</bean>
	<bean id="accountSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="accountDataSource" />
		<!-- 自动扫描mapping.xml文件 -->
		<property name="mapperLocations">
			<array>
				<value>classpath*:com/fujfu/dao/comuanda/mapping/*.xml</value>
			</array>
		</property>
	</bean>
	<!-- 扫描com.fujfu下的所有接口,然后创建各自接口的动态代理类 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
	    <property name="basePackage" 
	    value="com.fujfu.dao.admin,
	    com.fujfu.dao.app,
	    com.fujfu.dao.common,
	    com.fujfu.dao.focus,
	    com.fujfu.dao.news,
	    com.fujfu.dao.user" />  
	    <property name="sqlSessionFactory" ref="fuyhuiSqlSessionFactory"/>  
	</bean>  
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
	    <property name="basePackage" value="com.fujfu.dao.comuanda" />  
	    <property name="sqlSessionFactory" ref="accountSqlSessionFactory"/>  
	</bean>
    <!-- atomikos事务管理器 -->
    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">  
		<property name="forceShutdown">  
			<value>true</value>  
		</property>  
	</bean>
    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
		<property name="transactionTimeout" value="300" />  
	</bean>
    <bean id="springJTATransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">  
		<property name="transactionManager" ref="atomikosTransactionManager"/>  
        <property name="userTransaction" ref="atomikosUserTransaction" />  
        <property name="allowCustomIsolationLevels" value="true"/>  
	</bean>  
    <tx:annotation-driven transaction-manager="springJTATransactionManager"/>
	<!-- 这个content表示从指定的包去寻找组件<bean>("\"表示所有包),就不需要在此定义组件了<bean> -->
	<context:component-scan base-package="\" />
</beans>
到此,配置完毕。在service层的方法中使用@Transcation注解即可使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,基于Spring+SpringMVC+Mybatis+Mybatis plus等开源框架技术,我可以开发一个基于WEB的物流管理系统。下面是系统的一些功能: 1. 货物管理:包括货物的添加、修改、删除、查询等操作,可以对货物进行分类管理,以便进行更加精细的管理和查询。 2. 订单管理:包括订单的添加、修改、删除、查询等操作,可以对订单进行状态管理,以便进行更加精细的订单管理和查询。 3. 配送管理:包括配送员的管理、配送路线的规划、配送状态的管理等操作,可以对配送过程进行实时监控和管理。 4. 仓库管理:包括仓库的添加、修改、删除、查询等操作,可以对仓库进行分类管理,以便更好地进行库存管理和调度。 5. 用户管理:包括用户的添加、修改、删除、查询等操作,可以对用户进行权限管理,以便分配不同的操作权限给不同的用户。 针对这些功能,我可以使用Spring框架来实现系统的IOC和AOP功能,使用SpringMVC框架来实现系统的MVC架构,使用Mybatis框架来实现系统的ORM功能,使用Mybatis plus框架来进一步简化数据操作。 同时,我还可以使用其他开源技术来实现一些特定的功能,例如使用Redis实现缓存,使用Kafka实现消息队列等等,以提高系统的性能和可扩展性。 最终,开发出的物流管理系统将具备高效、稳定、安全、易扩展等特点,能够帮助企业实现物流管理的自动化和信息化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值