分布式事务

分布式事务,第1张

分布式事务

TC事务协调器

阿里工具state

业务案例

数据库初始化工具

1.新建Spring模块:db-init

2.添加依赖:

        spring  jdbc   --scriptUtils

        mysql  driver

3.yml配置数据库连接

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost/?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
    username: root
    password: root

4.在resource/sql/添加4个sql脚本文件

旧版本 mysql 5.x 修改脚本文件  DATATIME(6) -> DATETIME    (新版本  MARIEdb10.x不用) 

oredr.sql最后一行的now()改成0   (新版本 MARIEdb10.x不用)

SELECt VERSION()查看数据版本

5.在启动类中添加代码,执行这四个sql脚本

二、eureka注册中心 

1.新建spring模块:eureka

2.添加eureka server 依赖

 

3.yml

   禁用保护模式

   单台服务器不注册,不拉取

   端口:8761 

4.启动类添加注解:

@EnableEurekaServer

三、父项目

统一管理依赖

  1.新建maven模块:order-parent

  2.修改pom.xml 从笔记完整复制




    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.2.RELEASE
         
    
    cn.tedu
    order-parent
    1.0-SNAPSHOT
    pom
    order-parent


    
        3.3.2
        1.1.23
        1.3.0
        2.0.0.RELEASE
        Hoxton.SR12
    

    
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        

        
            com.baomidou
            mybatis-plus-boot-starter
            ${mybatis-plus.version}
        

        
            mysql
            mysql-connector-java
        
        
            com.alibaba
            druid-spring-boot-starter
            ${druid-spring-boot-starter.version}
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            org.projectlombok
            lombok
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



  3.删除src目录

四、业务模块---account、storage、order

    1.新建spring模块

 

    2.调整pom.xml,从order-parent继承

 

    3.yml配置

         application

spring:
  application:
    name: account

  datasource:
    url: jdbc:mysql://localhost/?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: root

server:
  port: 8081

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka

mybatis-plus:
  config-location: classpath:/mapper/*.xml
  type-aliases-package: cn.tedu.account.entity  #配置别名包
  configuration:
    map-underscore-to-camel-case: true  #驼峰命名

logging:
  level:
    cn.tedu.account.mapper: debug

         bootstrap

     4.实体类

     5.Mapper   启动类上添加注解 @MapperScan

     6.Service

        去掉依赖注入mapper接口下面小红线

     7.Controller

 8.测试访问localhost:8761 端口

访问账户服务执行账户扣减金额
访问 http://localhost:8081/decrease?userId=1&money=100

 

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5582807.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存