文档章节

Spring+Mybatis+SpringMVC+Atomikos多数据源共存+不同数据库事物一致性处理

傻男孩
 傻男孩
发布于 2017/05/23 11:54
字数 1949
阅读 93
收藏 1

项目结构说明:

1.dao层的admin、website包中包含的Mapper.xml文件分别操作不同的数据库

2.举例:192.168.1.1下有个mysql数据库叫 odao_admin

    192.168.1.2下有个sqlserver数据库叫 odao_mobile

    详情见下方的jdbc.properties文件

1:Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.odao.official</groupId>
  <artifactId>odao-official</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
    <name>odao-official website</name>  
    <url>http://maven.apache.org</url>  
      <properties>  
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
        <spring.version>4.1.6.RELEASE</spring.version>  
        <jackson.version>2.5.0</jackson.version>  
    </properties>
    <dependencies>  
        <!-- junit  --> 
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.12</version>  
            <scope>test</scope>  
        </dependency>  
        
        <!-- activemq  -->  
        <dependency>
              <groupId>org.apache.activemq</groupId>
              <artifactId>activemq-all</artifactId>
              <version>5.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-pool</artifactId>
            <version>5.9.0</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        
        <!-- spring  -->  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-core</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
        
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-beans</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-tx</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-web</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-jdbc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
          
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-test</artifactId>  
            <version>${spring.version}</version>  
            <scope>test</scope>  
        </dependency>  
        <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aop</artifactId>
              <version>${spring.version}</version>
        </dependency>
        <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
              <version>${spring.version}</version>
        </dependency>
              <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-context-support</artifactId>
              <version>${spring.version}</version>
        </dependency>
        
        <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-jms</artifactId>
              <version>${spring.version}</version>
        </dependency>
        <dependency>
              <groupId>org.apache.xbean</groupId>
              <artifactId>xbean-spring</artifactId>
              <version>4.2</version>
        </dependency>
        
        <!-- mybatis 包 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>3.2.8</version>  
        </dependency>  
  
        <!--mybatis spring 插件 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.2.2</version>  
        </dependency>  
  
        <!-- 数据源 -->  
        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>druid</artifactId>  
            <version>1.0.12</version>  
        </dependency>  
          
          <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        <dependency>  
            <groupId>org.aspectj</groupId>  
            <artifactId>aspectjweaver</artifactId>  
            <version>1.8.4</version>  
        </dependency>  
  
        <!-- log4j -->  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>1.2.17</version>  
        </dependency>  
  
        <!-- servlet 
        <dependency>  
            <groupId>javax.servlet</groupId>  
            <artifactId>servlet-api</artifactId>  
            <version>3.0-alpha-1</version>  
        </dependency>   --> 

        <dependency>  
            <groupId>javax.servlet</groupId>  
            <artifactId>jstl</artifactId>  
            <version>1.2</version>  
        </dependency>  
  
        <!-- json -->  
        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>fastjson</artifactId>  
            <version>1.2.3</version>  
        </dependency>
          
        <dependency>  
            <groupId>org.codehaus.jackson</groupId>  
            <artifactId>jackson-mapper-asl</artifactId>  
            <version>1.9.13</version>  
        </dependency>  
  
        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-annotations</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-core</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-databind</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  
        
        <!-- 文件上传 -->  
        <dependency>  
            <groupId>commons-io</groupId>  
            <artifactId>commons-io</artifactId>  
            <version>2.4</version>  
        </dependency>  
  
        <dependency>  
            <groupId>commons-fileupload</groupId>  
            <artifactId>commons-fileupload</artifactId>  
            <version>1.2.2</version>  
        </dependency>  
          
          <!-- ORM映射持久化 -->
          <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        
        <!-- sqlserver驱动 -->
        <dependency>
            <groupId>com.hynnet</groupId>
            <artifactId>sqljdbc4-chs</artifactId>
            <version>4.0.2206.100</version>
        </dependency>

        <!-- mysql驱动 -->  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
            <version>5.1.34</version>  
        </dependency>  
        
        <!-- atomikos -->
        <dependency>
              <groupId>com.atomikos</groupId>
              <artifactId>transactions-jdbc</artifactId>
              <version>3.7.0</version>
        </dependency>
        
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        

        <!-- cglib -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>3.2.2</version>
        </dependency>
        
    </dependencies>  
</project>

2:web.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    id="WebApp_ID" version="2.5">  
      <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
    <display-name>odao-official</display-name>  
  
    <!-- Spring Application Context Listener & spring-mybaits 
     -->
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:spring-mybatis.xml</param-value>  
    </context-param>  
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener> 
     
    <!-- Spring MVC Config -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
         <!-- Filter all resources -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <!-- Log4J -->
    <context-param>
            <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <!-- Spring Log4J config -->
    <listener>
         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
      </listener>
        
      <!-- Spring 编码过滤器  -->
    <filter>  
        <filter-name>characterEncoding</filter-name>  
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
        <init-param>  
            <param-name>encoding</param-name>  
            <param-value>utf-8</param-value>  
        </init-param>  
        <init-param>  
            <param-name>forceEncoding</param-name>  
            <param-value>true</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>characterEncoding</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
  
</web-app>

3:spring-mybatis.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:aop="http://www.springframework.org/schema/aop"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd  
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">    
    <!--引入配置属性文件 -->  
    <context:property-placeholder location="classpath:jdbc.properties" />
    
    <!-- 自动扫描 -->
    <context:component-scan base-package="com.odao" /> 
  
    <!-- 配置连接odao_mobile库的数据源 -->  
    <bean id="odaoMobile" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">  
        <!-- value只要两个数据源不同就行,随便取名 -->  
        <property name="uniqueResourceName" value="odaoMobileDB" />  
        <property name="driverClassName">  
            <value>${odaoMobile.jdbc.driver}</value>  
        </property>  
        <property name="url">  
            <value>${odaoMobile.jdbc.url}</value>  
        </property>  
        <property name="user">  
            <value>${odaoMobile.jdbc.username}</value>  
        </property>  
        <property name="password">  
            <value>${odaoMobile.jdbc.password}</value>  
        </property>  
    </bean>  
     
    <!-- 配置连接odao_admin库的数据源 -->
   <bean id="odaoAdmin" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">  
        <!-- value只要两个数据源不同就行,随便取名 -->  
        <property name="uniqueResourceName" value="odaoAdminDB" />  
       <property name="driverClassName">  
            <value>${odaoAdmin.jdbc.driver}</value>  
        </property>  
        <property name="url">  
            <value>${odaoAdmin.jdbc.url}</value>  
        </property>  
        <property name="user">  
            <value>${odaoAdmin.jdbc.username}</value>  
        </property>  
        <property name="password">  
            <value>${odaoAdmin.jdbc.password}</value>  
        </property>  
    </bean>  
    
    <bean id="webSiteSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="odaoMobile" />  
        <property name="mapperLocations" value="classpath:com/odao/dao/website/**/impl/*Mapper.xml" />  
    </bean>  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.odao.dao.website" />  
        <property name="sqlSessionFactoryBeanName" value="webSiteSqlSessionFactory" />  
    </bean>
    
    
    <bean id="adminSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="odaoAdmin" />  
        <property name="mapperLocations" value="classpath:com/odao/dao/admin/**/impl/*Mapper.xml" />  
    </bean>  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.odao.dao.admin" />  
        <property name="sqlSessionFactoryBeanName" value="adminSqlSessionFactory" />  
    </bean>    
    
    <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="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">  
        <property name="transactionManager">  
            <ref bean="atomikosTransactionManager"/>  
        </property>  
        <property name="userTransaction">  
            <ref bean="atomikosUserTransaction"/>  
        </property>  
        <!-- 必须设置,否则程序出现异常 JtaTransactionManager does not support custom isolation levels by default -->  
        <property name="allowCustomIsolationLevels" value="true"/>  
    </bean>  
  
      <aop:config proxy-target-class="true">  
        <aop:advisor pointcut="execution(* *com.odao.service..*(..))" advice-ref="txAdvice" />  
    </aop:config>  
   
    <tx:advice id="txAdvice" transaction-manager="transactionManager">  
        <tx:attributes>  
            <tx:method name="insert*"  propagation="REQUIRED"  read-only="true" />
            <tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />  
            <tx:method name="save*"  propagation="REQUIRED"  read-only="true" />    
            <tx:method name="delete*"  propagation="REQUIRED"  read-only="true" />  
            <tx:method name="del*"  propagation="REQUIRED"  read-only="true" />  
            <tx:method name="update*"  propagation="REQUIRED"  read-only="true" />  
        </tx:attributes>  
    </tx:advice>
      
</beans>

注意:上面配置的basePackage属性指定的不同的Mapper文件

4:spring-mvc.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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"  
    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://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">  
        
      <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
      <context:component-scan base-package="com.odao.controller" />
      
    <!-- 避免IE执行AJAX时,返回JSON出现下载文件  -->  
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean> 
  
    <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <!-- json转换器 -->  
                <ref bean="mappingJacksonHttpMessageConverter" />  
            </list>  
        </property>  
    </bean> 
  
    <!-- 定义跳转的文件的前后缀 ,视图模式配置-->  
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
           <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
           <property name="prefix" value="/WEB-INF/jsp/"/>
           <property name="suffix" value=".jsp"/>
       </bean>
  
    <!-- 配置多文件上传 -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <property name="defaultEncoding">  
            <value>UTF-8</value>  
        </property>  
        <property name="maxUploadSize">  
            <!-- 上传文件大小限制为31M,31*1024*1024 -->  
            <value>32505856</value>  
        </property>  
        <property name="maxInMemorySize">  
            <value>4096</value>  
        </property>  
    </bean>  
</beans>

5. jdbc.properties:

#mysql数据库链接
odaoAdmin.jdbc.driver=com.mysql.jdbc.Driver
odaoAdmin.jdbc.url=jdbc:mysql://192.168.1.1:3306/odao_admin?useUnicode=true&characterEncoding=utf8
odaoAdmin.jdbc.username=odao
odaoAdmin.jdbc.password=whattime

#sqlserver数据库链接
odaoMobile.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
odaoMobile.jdbc.url=jdbc:sqlserver://192.168.1.2:1433;DatabaseName=odao_mobile
odaoMobile.jdbc.username=sa
odaoMobile.jdbc.password=odao
validationQuery=SELECT 1

6.jta.properties:

com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.console_file_name = tm.out
com.atomikos.icatch.log_base_name = tmlog
com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm
com.atomikos.icatch.console_log_level =INFO

注意:jta.properties 文件在你复制的时候可能有空格,记得删掉

7:log4j.properties:

### set log levels ###  
log4j.rootLogger = Debug , C , D , E   
  
### console ###  
log4j.appender.C = org.apache.log4j.ConsoleAppender  
log4j.appender.C.Target = System.out  
log4j.appender.C.layout = org.apache.log4j.PatternLayout  
log4j.appender.C.layout.ConversionPattern = [springmvc_mybatis_demo][%p] [%-d{yyyy-MM-dd HH\:mm\:ss}] %C.%M(%L) | %m%n  
  
### log file ###  
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.D.File = ../logs/springmvc-mybatis-demo.log  
log4j.appender.D.Append = true  
log4j.appender.D.Threshold = INFO   
log4j.appender.D.layout = org.apache.log4j.PatternLayout  
log4j.appender.D.layout.ConversionPattern = [springmvc_mybatis_demo][%p] [%-d{yyyy-MM-dd HH\:mm\:ss}] %C.%M(%L) | %m%n  
  
### exception ###  
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.E.File = ../logs/springmvc-mybatis-demo_error.log   
log4j.appender.E.Append = true  
log4j.appender.E.Threshold = ERROR   
log4j.appender.E.layout = org.apache.log4j.PatternLayout  
log4j.appender.E.layout.ConversionPattern =[sspringmvc_mybatis_demo][%p] [%-d{yyyy-MM-dd HH\:mm\:ss}] %C.%M(%L) | %m%n

8. 控制层 UserInfoController.java :

package com.odao.controller.user;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.odao.entity.UserInfo;
import com.odao.service.website.UserService;

@Controller  
@RequestMapping("/user/") 
public class UserInfoController {
    
    @Autowired  
    private UserService userService;  
    
    @RequestMapping("userInfoList.do")  
    public ModelAndView getUserInfoList(HttpServletRequest request, HttpServletResponse response){  
        ModelAndView modelAndView = new ModelAndView("user/userInfoList");
        List<UserInfo> userInfoList = userService.selectAll();  
        List<UserInfo> userInfo = userService.selectUser();
        modelAndView.addObject("userName",userInfoList.get(0).getTest_id()+"===="+userInfo.get(0).getTest_name());  
        return modelAndView;
    }
    
    @ResponseBody
    @RequestMapping("updateUserInfo.do")  
    public ModelAndView updateUserInfo(HttpServletRequest request, HttpServletResponse response){  
        ModelAndView modelAndView = new ModelAndView("user/userInfoList");
        UserInfo user = new UserInfo();
        user.setTest_id(1);
        user.setTest_name("嗯~有耐心看到这里的都帅");;
        userService.saveUser(user);
        return modelAndView;
    }
}

9.业务逻辑层:UserService.java:

package com.odao.service.website;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.odao.dao.admin.user.AdminUserInfoDao;
import com.odao.dao.website.user.WebSiteUserInfoDao;
import com.odao.entity.UserInfo;

@Service
public class UserService  {

    @Autowired  
    private WebSiteUserInfoDao websiteUserInfoDao;
    
    @Autowired  
    private AdminUserInfoDao adminUserInfoDao;
    
    public List<UserInfo> selectAll() {
        return websiteUserInfoDao.selectAll();
    }
    
    public List<UserInfo> selectUser() {
        return adminUserInfoDao.selectUser();
    }
    

    public void saveUser(UserInfo userInfo){
        websiteUserInfoDao.saveUser(userInfo);
     //测试操作不同数据库时,事物回滚的一致性(要么都成功,要么都失败)
     if(1==1){
            throw new NullPointerException();
        }
        adminUserInfoDao.saveUser(userInfo);
    }
    
}

整个项目大致就这样,entity跟dao就不贴了,你们看方法也能猜到,图片上的transaction-context.xml文件内容我给弄到了spring-mybatis.xml里面,就是一些关于分布式事物的

© 著作权归作者所有

傻男孩
粉丝 2
博文 47
码字总数 52350
作品 0
深圳
高级程序员
私信 提问
mysql锁知识小了解

一、概述 mysql的锁分为表锁和行锁两种,其中myisam引擎用的是表锁, innoDB默认的使用是行锁, 其他情况是表锁。 两种锁的优缺点: 表级锁:加锁速度快,开销小。不会出现死锁的情况,粒度大...

GuoYJ
2015/09/13
214
0
分布式系统简介

什么是分布式系统 分布式系统(distributed system)具有高度的 内聚性 和 透明性。 内聚性:每一个节点高度自治,有本地的数据库管理系统; 透明性:每一个数据库分布节点对用户来说是透明的...

暮回_梓
2017/09/16
0
0
很久没发贴了,谈个数据层的东西

信息资源与基础数据探讨 吉 星 摘要 针对智慧城市中公共信息平台建设、电子政务中信息资源规划所面对的数据/信息整合工作所存在的信息孤岛/烟囱的问题,本文从数据的角度进行分析,并对主题...

中山野鬼
2013/05/09
826
11
JDBC--处理事务与隔离级别

一、事务 在数据库中,所谓事务是指一组逻辑操作单元,使数据从一种状态变换到另一种状态。 (1)事务的ACID(acid)属性 1. 原子性(Atomicity) 原子性是指事务是一个不可分割的工作单位,事务...

大道无名
2016/07/02
74
0
数据库分库分表(sharding)系列(四) 多数据源的事务处理

系统经sharding改造之后,原来单一的数据库会演变成多个数据库,如何确保多数据源同时操作的原子性和一致性是不得不考虑的一个问题。总体上看,目前对于一个分布式系统的事务处理有三种方式:...

bluishglc
2012/07/27
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Spring Cloud 笔记之Spring cloud config client

观察者模式它的数据的变化是被动的。 观察者模式在java中的实现: package com.hxq.springcloud.springcloudconfigclient;import org.springframework.context.ApplicationListener;i...

xiaoxiao_go
昨天
4
0
CentOS7.6中安装使用fcitx框架

内容目录 一、为什么要使用fcitx?二、安装fcitx框架三、安装搜狗输入法 一、为什么要使用fcitx? Gnome3桌面自带的输入法框架为ibus,而在使用ibus时会时不时出现卡顿无法输入的现象。 搜狗和...

技术训练营
昨天
4
0
《Designing.Data-Intensive.Applications》笔记 四

第九章 一致性与共识 分布式系统最重要的的抽象之一是共识(consensus):让所有的节点对某件事达成一致。 最终一致性(eventual consistency)只提供较弱的保证,需要探索更高的一致性保证(stro...

丰田破产标志
昨天
7
0
docker 使用mysql

1, 进入容器 比如 myslq1 里面进行操作 docker exec -it mysql1 /bin/bash 2. 退出 容器 交互: exit 3. mysql 启动在容器里面,并且 可以本地连接mysql docker run --name mysql1 --env MY...

之渊
昨天
7
0
python数据结构

1、字符串及其方法(案例来自Python-100-Days) def main(): str1 = 'hello, world!' # 通过len函数计算字符串的长度 print(len(str1)) # 13 # 获得字符串首字母大写的...

huijue
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部