springcloud+mybatis+seate 통합 예시

클 라 이언 트
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
 서버
1.seata-server 다운로드
[seata-server]{https://github.com/seata/seata/releases}
2.프로필 수정(본 고 는 nacos 를 예 로 들 고 store 는 my sql 로 기록 합 니 다)
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 의 server Addr 를 설정 하여 nacos 서비스의 주 소 를 설정 합 니 다.http 와 포트 번 호 를 가지 고 있 지 마 십시오.포트 를 수정 하려 면 nacos-config.sh 파일 의 포트 를 수정 하 십시오.
seata 서 비 스 를 사용 하 는 모든 resources 에 registry.conf 를 복사 합 니 다.
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 로 변경 하고 db 설정 파일 을 자신의 my sql 로 변경 합 니 다.
service.vgroup 수정mapping.my_test_tx_group=default 속성
0.9.0.1 버 전 후:mytest_tx_group 이 자신의 서비스 이름(spring.application.name)+"-seata-service-group"으로 변경 되 었 습 니 다.
이전 버 전:mytest_tx_group 은 자신의 서비스 이름(spring.application.name)+"-fescar-service-group"으로 변경 합 니 다.
spring-cloud-alibaba-seta 프로젝트 의 GlobalTransactionAutoConfiguration 누적 중 볼 수 있 습 니 다.

seata 를 사용 해 야 하 는 서비스 가 몇 개 있 으 면 service.vgroup 를 추가 해 야 합 니까?mapping
nacos-config.sh Nacos-Server-IP(?tex-Nacos-Server-IP( Nacos-Server-IP nacos ip ),를 실행 하 는 단 계 는 nacos-config.txt 의 설정 을 nacos 에 업데이트 하 는 것 입 니 다.nacos-config.txt 를 다시 수정 하면 이 명령 을 다시 실행 해 야 합 니 다.또는 nacos 관리 인터페이스 에 로그 인하 여 직접 수정 합 니 다.
이후 추가,삭제,서비스 수정,nacos 설정 에 대응 하 는 수정 을 하면 됩 니 다.
3.테이블 만 들 기
이전 단계 에서 store.db.url 의 database 에서 표 문 구 를 실행 합 니 다(conf 아래 dbstore.sql)
모든 업무 라 이브 러 리 에서 테이블 문 구 를 실행 합 니 다(conf 아래 dbundo_log.sql)
 본문 링크:https://gudepeng.github.io/note/2019/11/29/seate/
demo 샘플:https://github.com/gudepeng/demoproject/tree/master/seata-servicea
springcloud+my batis+seate 통합 예제 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 springcloud my batis seate 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 도 많은 응원 부 탁 드 리 겠 습 니 다!

좋은 웹페이지 즐겨찾기