欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springcloud + mybatis + seate集成示例

 更新時間:2021年06月30日 15:13:22   作者:我是金角大王  
本文主要介紹了springcloud + mybatis + seate集成示例,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一.客戶端

1.引包

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
    <version>2.1.1.RELEASE</version>
</dependency>

 2.編寫配置類

@Configuration
public class DataSourceConfig {

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        return druidDataSource;
    }

    @Primary
    @Bean("dataSource")
    public DataSourceProxy dataSource(DataSource druidDataSource) {
        return new DataSourceProxy(druidDataSource);
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(dataSourceProxy);
        factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
            .getResources("classpath*:/mapper/*.xml"));
        return factoryBean.getObject();
    }
}

 3.修改啟動類

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

 4.在需要開啟分布式事物的方法上添加注解

@GlobalTransactional

 二.服務(wù)端

1.下載seata-server

[seata-server]{https://github.com/seata/seata/releases}

2.修改配置文件(本文以nacos為樣例,store記錄為mysql)

修改conf下的registry.conf

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"

  nacos {
    serverAddr = "localhost"
    namespace = "piblic"
    cluster = "default"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"

  nacos {
    serverAddr = "localhost"
    #namespace為空,否則后面會報找不到store.db.driver-class-name找不到
    namespace = ""
  }
}

修改registry下的type為nacos,配置nacos的serverAddr為你nacos服務(wù)的地址,不要帶http和端口號。它會默認(rèn)去連你的8858端口,如需修改端口,請修改nacos-config.sh文件中的端口
拷貝registry.conf到每個使用seata服務(wù)的resources下
修改conf下nacos-config.txt

store.mode=db
store.db.datasource=dbcp
store.db.db-type=mysql
store.db.driver-class-name=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=mysql
store.db.password=mysql

修改store.mode為db,修改對應(yīng)db配置文件為你自己的mysql。
修改service.vgroup_mapping.my_test_tx_group=default屬性
0.9.0.1版本后:my_test_tx_group修改為自己的服務(wù)名(spring.application.name)+"-seata-service-group"
0.9.0.1版本前:my_test_tx_group修改為自己的服務(wù)名(spring.application.name)+"-fescar-service-group"
可以spring-cloud-alibaba-seata項目下的GlobalTransactionAutoConfiguration累中看到

有多少個服務(wù)需要使用seata就要添加多少個ervice.vgroup_mapping
執(zhí)行nacos-config.sh Nacos-Server-IP(?tex-Nacos-Server-IP( Nacos-Server-IP為你nacos服務(wù)的ip地址),在一步驟是把nacos-config.txt中的配置更新到nacos上,如果nacos-config.txt重新修改,就要重新執(zhí)行該命令?;蛘叩顷懙絥acos的管理界面直接進(jìn)行修改。
之后添加,刪除,修改服務(wù),在nacos配置上作對應(yīng)修改即可

3.創(chuàng)建表

在上一步驟中store.db.url的database中執(zhí)行建表語句(conf下db_store.sql)
在每一個業(yè)務(wù)庫中執(zhí)行建表語句(conf下db_undo_log.sql)

 本文鏈接:https://gudepeng.github.io/note/2019/11/29/seate/
demo樣例:https://github.com/gudepeng/demoproject/tree/master/seata-servicea

到此這篇關(guān)于springcloud + mybatis + seate集成示例的文章就介紹到這了,更多相關(guān)springcloud mybatis seate內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論