zoukankan      html  css  js  c++  java
  • springcloud alibaba 集成seata1.3

    下面只写出我的正确运行的集成环境,

    1、版本要正确,不然报的错你都不知道为什么

    <dependencyManagement>
    <dependencies>
    <!-- 导入Spring Cloud的依赖管理 -->
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Hoxton.SR8</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    <dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.2.4.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>

    2、集成seata

    <!--seata-->
    <dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
    <exclusions>
    <exclusion>
    <groupId>io.seata</groupId>
    <artifactId>seata-spring-boot-starter</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>io.seata</groupId>
    <artifactId>seata-spring-boot-starter</artifactId>
    <version>1.3.0</version>
    </dependency>

    3、代理数据源

    @Configuration
    public class DataSourceConfiguration {


    @Value("${mybatis-plus.mapper-locations}")
    private String mapperLocations;

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

    @Bean
    public DataSourceProxy dataSourceProxy(DataSource dataSource) {
    return new DataSourceProxy(dataSource);
    }

    @Bean(name = "TCTransactionManager")
    public DataSourceTransactionManager transactionManager(@Autowired DruidDataSource dataSource) {
    return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean (); //这里用到了mybatis-plus,如果只是mybaits就用SqlSessionFactoryBean
    sqlSessionFactoryBean.setDataSource(dataSourceProxy);

    4、启动类排除

    @SpringBootApplication(exclude = {MultipartAutoConfiguration.class,DataSourceAutoConfiguration.class})

    5、file.conf 和registry.conf 与下载包里一致就可以了

    6、目前个人发现要回滚,需要加try

  • 相关阅读:
    C#磁吸屏幕窗体类库
    准备
    我写的诗
    How to turn off a laptop keyboard
    How to tell which commit a tag points to in Git?
    Why should I care about lightweight vs. annotated tags?
    How to get rid of “would clobber existing tag”
    Facebook, Google and Twitter threaten to leave Hong Kong over privacy law changes
    The need for legislative reform on secrecy orders
    Can a foreign key be NULL and/or duplicate?
  • 原文地址:https://www.cnblogs.com/xgyweb/p/14302314.html
Copyright © 2011-2022 走看看