springboot集成seata
时间: 2023-11-23 11:08:25 浏览: 162
在Spring Boot中集成Seata,需要进行以下步骤:
1.添加Seata的依赖。在pom.xml文件中添加以下依赖:
```xml
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>${seata.version}</version>
</dependency>
```
2.配置Seata。在application.properties或application.yml文件中添加以下配置:
```yaml
spring:
application:
name: ${spring.application.name}
cloud:
alibaba:
seata:
tx-service-group: ${spring.application.name}-fescar-service-group
seata:
enabled: true
application-id: ${spring.application.name}
tx-service-group: ${spring.application.name}-fescar-service-group
config:
type: nacos
nacos:
serverAddr: ${nacos.server-addr:localhost:8848}
namespace: ${nacos.namespace:public}
registry:
type: nacos
nacos:
serverAddr: ${nacos.server-addr:localhost:8848}
namespace: ${nacos.namespace:public}
service:
vgroupMapping:
${spring.application.name}-fescar-service-group: default
groupMapping:
${spring.application.name}-fescar-service-group: "default"
transport:
type: TCP
tcp:
selector: ${seata.selector:org.apache.seata.core.rpc.netty.NettyClientConfig}
clientWorkerThreads: ${seata.client.worker.thread.size:NettyRuntime.availableProcessors()}
bossThreadSize: ${seata.boss.thread.size:1}
shutdownWait: ${seata.shutdown.wait:3}
maxConnection: ${seata.max.commit.retry.timeout:1}
connectionWaitTimeout: ${seata.max.commit.retry.timeout:5000}
idleTimeout: ${seata.max.commit.retry.timeout:300000}
heartbeatTimeout: ${seata.heartbeat.timeout:1000}
```
3.配置数据源。在application.properties或application.yml文件中添加以下配置:
```yaml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
```
4.配置MyBatis。在MyBatis的配置文件中添加以下配置:
```xml
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<package name="com.xxx.xxx.entity"/>
</typeAliases>
<plugins>
<plugin interceptor="io.seata.rm.datasource.mybatis.SeataInterceptor"/>
</plugins>
</configuration>
```
5.启动Seata Server。在Seata Server的bin目录下执行以下命令:
```shell
sh seata-server.sh -p 8091 -m file
```
6.启动应用程序。在Spring Boot应用程序的启动类上添加@SeataApplication注解。
```java
@SpringBootApplication
@SeataApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
阅读全文
相关推荐
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)