puzhibing
2026-02-06 688d3c200cb9ca0ae113e123c064a17e5c76cbcb
集成shardingsphere-jdbc和seata分布式事务
12个文件已添加
4个文件已修改
130 ■■■■■ 已修改文件
pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/pom.xml 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-account/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-automaticPilot/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-itinerary/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-maintenance/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-map/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-operation/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-order/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-payment/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-pushMessage/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-remoteDriving/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-vehicleConvoy/src/main/java/com/xiaopeng/vehicleConvoy/config/MessageLocalConfig.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-vehicleConvoy/src/main/java/com/xiaopeng/vehicleConvoy/config/TransactionConfiguration.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-vehicleConvoy/src/main/resources/bootstrap.yml 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-service/xp-vehicleConvoy/src/main/resources/seata.conf 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -39,7 +39,6 @@
        <minio.version>8.2.2</minio.version>
        <poi.version>4.1.2</poi.version>
        <transmittable-thread-local.version>2.14.2</transmittable-thread-local.version>
        <shardingsphere.version>5.5.2</shardingsphere.version>
    </properties>
    <!-- 依赖声明 -->
@@ -214,11 +213,6 @@
                <groupId>com.xiaopeng</groupId>
                <artifactId>xp-api-account</artifactId>
                <version>${xp.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.shardingsphere</groupId>
                <artifactId>shardingsphere-jdbc</artifactId>
                <version>${shardingsphere.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
xp-service/pom.xml
@@ -30,22 +30,6 @@
    </description>
    <dependencies>
        <!-- easypoi -->
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>4.4.0</version>
        </dependency>
        <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
@@ -66,6 +50,17 @@
            <artifactId>unified-verification</artifactId>
            <version>1.5.2-v2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
            <version>5.0.0</version>
        </dependency>
        <!-- 使用 BASE 事务时,需要引入此模块 -->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-transaction-base-seata-at</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>
</project>
xp-service/xp-account/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-account"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-automaticPilot/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-automaticPilot"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-itinerary/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-itinerary"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-maintenance/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-maintenance"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-map/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-map"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-operation/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-operation"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-order/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-order"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-payment/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-payment"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-pushMessage/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-pushMessage"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-remoteDriving/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-remoteDriving"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}
xp-service/xp-vehicleConvoy/src/main/java/com/xiaopeng/vehicleConvoy/config/MessageLocalConfig.java
@@ -9,6 +9,8 @@
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@@ -19,6 +21,18 @@
public class MessageLocalConfig {
    @Bean
    public MessageSourceProperties messageSourceProperties() {
        MessageSourceProperties properties = new MessageSourceProperties();
        properties.setBasename("i18n/messages");
        properties.setEncoding(StandardCharsets.UTF_8);
        properties.setFallbackToSystemLocale(false);
        properties.setCacheDuration(Duration.ofSeconds(-1));
        properties.setAlwaysUseMessageFormat(false);
        properties.setUseCodeAsDefaultMessage(true);
        return properties;
    }
    @Bean
    public MessageSource messageSource(MessageSourceProperties properties) {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        if (StringUtils.hasText(properties.getBasename())) {
xp-service/xp-vehicleConvoy/src/main/java/com/xiaopeng/vehicleConvoy/config/TransactionConfiguration.java
New file
@@ -0,0 +1,27 @@
package com.xiaopeng.vehicleConvoy.config;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
 * 分布式事务配置
 */
@Configuration
@EnableTransactionManagement
public class TransactionConfiguration {
    @Bean
    public PlatformTransactionManager txManager(final DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
    @Bean
    public JdbcTemplate jdbcTemplate(final DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
xp-service/xp-vehicleConvoy/src/main/resources/bootstrap.yml
@@ -159,3 +159,4 @@
        shared-configs:
          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
---
xp-service/xp-vehicleConvoy/src/main/resources/seata.conf
New file
@@ -0,0 +1,5 @@
# seata.conf
client {
    application.id = "xp-vehicleConvoy"  # 与spring.application.name一致
    transaction.service.group = "seata_tx_group"
}