mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 spring cloud alibaba seata 示例
This commit is contained in:
@@ -4,7 +4,7 @@ import cn.iocoder.springboot.lab53.accountservice.api.AccountService;
|
||||
import cn.iocoder.springboot.lab53.orderservice.api.OrderService;
|
||||
import cn.iocoder.springboot.lab53.orderservice.dao.OrderDao;
|
||||
import cn.iocoder.springboot.lab53.orderservice.entity.OrderDO;
|
||||
import cn.iocoder.springboot.lab53.storageservice.api.ProductService;
|
||||
import cn.iocoder.springboot.lab53.productservice.api.ProductService;
|
||||
import io.seata.core.context.RootContext;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.storageservice.api;
|
||||
package cn.iocoder.springboot.lab53.productservice.api;
|
||||
|
||||
/**
|
||||
* 商品 Service
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.springboot.lab53.productservice.service;
|
||||
|
||||
import cn.iocoder.springboot.lab53.productservice.dao.ProductDao;
|
||||
import cn.iocoder.springboot.lab53.storageservice.api.ProductService;
|
||||
import cn.iocoder.springboot.lab53.productservice.api.ProductService;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-order-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-order-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-account-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring MVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 MyBatis 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Seata 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Dubbo 的依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
<!-- 实现对 Dubbo 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
<!-- 实现 Dubbo 使用 Nacos 作为注册中心 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
<version>2.7.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter 基础库 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 MyBatis 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Seata 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Dubbo 的依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
<!-- 实现对 Dubbo 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
<!-- 实现 Dubbo 使用 Nacos 作为注册中心 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
<version>2.7.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -8,21 +8,27 @@ spring:
|
||||
username: root
|
||||
password:
|
||||
|
||||
cloud:
|
||||
# Nacos 作为注册中心的配置项
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: ${spring.application.name} # 应用名
|
||||
# Dubbo 注册中心配
|
||||
# Dubbo 服务注册中心配置,对应 RegistryConfig 类
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab53.accountservice.service
|
||||
base-packages: cn.iocoder.springcloudalibaba.labx17.accountservice.service
|
||||
# Spring Cloud Alibaba Dubbo 专属配置项,对应 DubboCloudProperties 类
|
||||
cloud:
|
||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用。
|
||||
|
||||
# Seata 配置项,对应 SeataProperties 类
|
||||
seata:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice.api;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice.api;
|
||||
|
||||
/**
|
||||
* 订单 Service
|
||||
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-order-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
|
||||
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>
|
||||
</properties>
|
||||
|
||||
<!--
|
||||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。
|
||||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系
|
||||
-->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring.cloud.alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-order-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-account-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring MVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 MyBatis 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Seata 相关依赖,使用 Seata 实现分布式事务,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Nacos Discovery 相关依赖,将 Nacos 作为注册中心,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Dubbo 相关依赖,实现呢 Dubbo 进行远程调用,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice.controller;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice.controller;
|
||||
|
||||
import cn.iocoder.springboot.lab53.orderservice.api.OrderService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.orderservice.api.OrderService;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice.dao;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice.dao;
|
||||
|
||||
import cn.iocoder.springboot.lab53.orderservice.entity.OrderDO;
|
||||
import cn.iocoder.springcloudalibaba.labx17.orderservice.entity.OrderDO;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice.entity;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice.entity;
|
||||
|
||||
/**
|
||||
* 订单实体
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.iocoder.springboot.lab53.orderservice.service;
|
||||
package cn.iocoder.springcloudalibaba.labx17.orderservice.service;
|
||||
|
||||
import cn.iocoder.springboot.lab53.accountservice.api.AccountService;
|
||||
import cn.iocoder.springboot.lab53.orderservice.api.OrderService;
|
||||
import cn.iocoder.springboot.lab53.orderservice.dao.OrderDao;
|
||||
import cn.iocoder.springboot.lab53.orderservice.entity.OrderDO;
|
||||
import cn.iocoder.springboot.lab53.storageservice.api.ProductService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.accountservice.api.AccountService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.orderservice.api.OrderService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.orderservice.dao.OrderDao;
|
||||
import cn.iocoder.springcloudalibaba.labx17.orderservice.entity.OrderDO;
|
||||
import cn.iocoder.springcloudalibaba.labx17.producctservice.api.ProductService;
|
||||
import io.seata.core.context.RootContext;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
@@ -11,21 +11,27 @@ spring:
|
||||
username: root
|
||||
password:
|
||||
|
||||
cloud:
|
||||
# Nacos 作为注册中心的配置项
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: ${spring.application.name} # 应用名
|
||||
# Dubbo 注册中心配
|
||||
# Dubbo 服务注册中心配置,对应 RegistryConfig 类
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab53.orderservice.service
|
||||
base-packages: cn.iocoder.springcloudalibaba.labx17.orderservice.service
|
||||
# Spring Cloud Alibaba Dubbo 专属配置项,对应 DubboCloudProperties 类
|
||||
cloud:
|
||||
subscribed-services: account-service, product-service # 设置订阅的应用列表,默认为 * 订阅所有应用。
|
||||
|
||||
# Seata 配置项,对应 SeataProperties 类
|
||||
seata:
|
||||
@@ -11,21 +11,27 @@ spring:
|
||||
username: root
|
||||
password:
|
||||
|
||||
cloud:
|
||||
# Nacos 作为注册中心的配置项
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: ${spring.application.name} # 应用名
|
||||
# Dubbo 注册中心配
|
||||
# Dubbo 服务注册中心配置,对应 RegistryConfig 类
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab53.orderservice.service
|
||||
base-packages: cn.iocoder.springcloudalibaba.labx17.orderservice.service
|
||||
# Spring Cloud Alibaba Dubbo 专属配置项,对应 DubboCloudProperties 类
|
||||
cloud:
|
||||
subscribed-services: account-service, product-service # 设置订阅的应用列表,默认为 * 订阅所有应用。
|
||||
|
||||
# Seata 配置项,对应 SeataProperties 类
|
||||
seata:
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.storageservice.api;
|
||||
package cn.iocoder.springcloudalibaba.labx17.producctservice.api;
|
||||
|
||||
/**
|
||||
* 商品 Service
|
||||
@@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
|
||||
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>
|
||||
</properties>
|
||||
|
||||
<!--
|
||||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。
|
||||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系
|
||||
-->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring.cloud.alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>labx-17-sca-seata-at-dubbo-demo-product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter 基础库 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 MyBatis 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Seata 相关依赖,使用 Seata 实现分布式事务,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Nacos Discovery 相关依赖,将 Nacos 作为注册中心,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Cloud Alibaba Dubbo 相关依赖,实现呢 Dubbo 进行远程调用,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.productservice;
|
||||
package cn.iocoder.springcloudalibaba.labx17.productservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.springboot.lab53.productservice.dao;
|
||||
package cn.iocoder.springcloudalibaba.labx17.productservice.dao;
|
||||
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.springboot.lab53.productservice.service;
|
||||
package cn.iocoder.springcloudalibaba.labx17.productservice.service;
|
||||
|
||||
import cn.iocoder.springboot.lab53.productservice.dao.ProductDao;
|
||||
import cn.iocoder.springboot.lab53.storageservice.api.ProductService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.producctservice.api.ProductService;
|
||||
import cn.iocoder.springcloudalibaba.labx17.productservice.dao.ProductDao;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -8,21 +8,27 @@ spring:
|
||||
username: root
|
||||
password:
|
||||
|
||||
cloud:
|
||||
# Nacos 作为注册中心的配置项
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: ${spring.application.name} # 应用名
|
||||
# Dubbo 注册中心配
|
||||
# Dubbo 服务注册中心配置,对应 RegistryConfig 类
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab53.productservice.service
|
||||
base-packages: cn.iocoder.springcloudalibaba.labx17.productservice.service
|
||||
# Spring Cloud Alibaba Dubbo 专属配置项,对应 DubboCloudProperties 类
|
||||
cloud:
|
||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用。
|
||||
|
||||
# Seata 配置项,对应 SeataProperties 类
|
||||
seata:
|
||||
@@ -8,21 +8,27 @@ spring:
|
||||
username: root
|
||||
password:
|
||||
|
||||
cloud:
|
||||
# Nacos 作为注册中心的配置项
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: ${spring.application.name} # 应用名
|
||||
# Dubbo 注册中心配
|
||||
# Dubbo 服务注册中心配置,对应 RegistryConfig 类
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab53.productservice.service
|
||||
base-packages: cn.iocoder.springcloudalibaba.labx17.productservice.service
|
||||
# Spring Cloud Alibaba Dubbo 专属配置项,对应 DubboCloudProperties 类
|
||||
cloud:
|
||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用。
|
||||
|
||||
# Seata 配置项,对应 SeataProperties 类
|
||||
seata:
|
||||
@@ -14,6 +14,10 @@
|
||||
<modules>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-account-service-api</module>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-account-service</module>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-product-service-api</module>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-product-service</module>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-order-service-api</module>
|
||||
<module>labx-17-sca-seata-at-dubbo-demo-order-service</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user