Spring Cloud Alibaba整合Seata实战
@Configuration
public class SeataAutoConfiguration {
@Value("${spring.cloud.alibaba.seata.tx-service-group}")
private String txServiceGroup;
@Bean
public GlobalTransactionScanner globalTransactionScanner() {
GlobalTransactionScanner scanner = new GlobalTransactionScanner(txServiceGroup, null);
scanner.setSpringManagedTransactionFactory(new SeataManagedTransactionFactory());
return scanner;
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
这个配置类用于定义Seata全局事务扫描器,它会自动将标记了@GlobalTransactional的方法包装在Seata分布式事务中。同时,它提供了一个RestTemplate的Bean,该Bean已经配置了负载均衡器,可以用于服务间的REST调用。这个配置类可以被用作Spring Cloud Alibaba整合Seata的基础。
评论已关闭