diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml
index 9b4a4316d..8cb328656 100644
--- a/yudao-dependencies/pom.xml
+++ b/yudao-dependencies/pom.xml
@@ -222,6 +222,13 @@
${redisson.version}
+
+
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc
+ ${revision}
+
+
diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml
index a5850bd42..e13419176 100644
--- a/yudao-framework/pom.xml
+++ b/yudao-framework/pom.xml
@@ -21,6 +21,7 @@
yudao-spring-boot-starter-protection
yudao-spring-boot-starter-job
yudao-spring-boot-starter-mq
+ yudao-spring-boot-starter-rpc
yudao-spring-boot-starter-excel
yudao-spring-boot-starter-test
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml b/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml
new file mode 100644
index 000000000..42389560c
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+ yudao-framework
+ cn.iocoder.cloud
+ ${revision}
+
+ 4.0.0
+ yudao-spring-boot-starter-rpc
+ jar
+
+ ${project.artifactId}
+
+ OpenFeign:提供 RESTful API 的调用
+ Dubbo:提供 Dubbo RPC 的调用
+
+ https://github.com/YunaiV/ruoyi-vue-pro
+
+
+
+ cn.iocoder.cloud
+ yudao-common
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-dubbo
+
+
+
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java
new file mode 100644
index 000000000..516acc537
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * 占坑 TODO
+ */
+package cn.iocoder.yudao.framework.rpc.config;
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java
new file mode 100644
index 000000000..e8e494628
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * 占坑 TODO
+ */
+package cn.iocoder.yudao.framework.rpc.core;
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java
new file mode 100644
index 000000000..af81e0be6
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java
@@ -0,0 +1,48 @@
+package cn.iocoder.yudao.framework.rpc.core.util;
+
+import cn.hutool.core.util.ReflectUtil;
+import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
+import feign.RequestTemplate;
+import feign.template.HeaderTemplate;
+import feign.template.Literal;
+import feign.template.Template;
+import feign.template.TemplateChunk;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * {@link feign.Feign} 工具类
+ *
+ * @author 芋道源码
+ */
+public class FeignUtils {
+
+ /**
+ * 添加 JSON 格式的 Header
+ *
+ * @param requestTemplate 请求
+ * @param name header 名
+ * @param value header 值
+ */
+ @SuppressWarnings("unchecked")
+ public static void createJsonHeader(RequestTemplate requestTemplate, String name, Object value) {
+ if (value == null) {
+ return;
+ }
+ // 添加 header
+ String valueStr = JsonUtils.toJsonString(value);
+ requestTemplate.header(name, valueStr);
+ // fix:由于 OpenFeign 针对 { 会进行分词,所以需要反射修改
+ // 具体分析,可见 https://zhuanlan.zhihu.com/p/360501330 文档
+ Map headers = (Map)
+ ReflectUtil.getFieldValue(requestTemplate, "headers");
+ HeaderTemplate template = headers.get(name);
+ List templateValues = (List)
+ ReflectUtil.getFieldValue(template, "values");
+ List templateChunks = (List)
+ ReflectUtil.getFieldValue(templateValues.get(0), "templateChunks");
+ templateChunks.set(0, Literal.create(valueStr));
+ }
+
+}
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/package-info.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/package-info.java
new file mode 100644
index 000000000..004f14d37
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/package-info.java
@@ -0,0 +1,7 @@
+/**
+ * OpenFeign:提供 RESTful API 的调用
+ * Dubbo:提供 Dubbo RPC 的调用
+ *
+ * @author 芋道源码
+ */
+package cn.iocoder.yudao.framework.rpc;
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot Dubbo 入门》.md b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot Dubbo 入门》.md
new file mode 100644
index 000000000..b799667ba
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot Dubbo 入门》.md
@@ -0,0 +1 @@
+
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot 声明式调用 Feign 入门》.md b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot 声明式调用 Feign 入门》.md
new file mode 100644
index 000000000..6df6a3801
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Boot 声明式调用 Feign 入门》.md
@@ -0,0 +1 @@
+
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》.md b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》.md
new file mode 100644
index 000000000..8e4566c15
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》.md
@@ -0,0 +1 @@
+
diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud 声明式调用 Feign 入门》.md b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud 声明式调用 Feign 入门》.md
new file mode 100644
index 000000000..b419fd006
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-rpc/《芋道 Spring Cloud 声明式调用 Feign 入门》.md
@@ -0,0 +1 @@
+
diff --git a/yudao-framework/yudao-spring-boot-starter-security/pom.xml b/yudao-framework/yudao-spring-boot-starter-security/pom.xml
index 40d83d633..e28424430 100644
--- a/yudao-framework/yudao-spring-boot-starter-security/pom.xml
+++ b/yudao-framework/yudao-spring-boot-starter-security/pom.xml
@@ -53,17 +53,9 @@
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-dubbo
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc
+ true
diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityFeignAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityRpcAutoConfiguration.java
similarity index 58%
rename from yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityFeignAutoConfiguration.java
rename to yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityRpcAutoConfiguration.java
index a2b5c6ae7..a9a92e8cf 100644
--- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityFeignAutoConfiguration.java
+++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityRpcAutoConfiguration.java
@@ -1,8 +1,11 @@
package cn.iocoder.yudao.framework.security.config;
+import cn.iocoder.yudao.framework.security.core.rpc.LoginUserRequestInterceptor;
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
@@ -13,5 +16,11 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {OAuth2TokenApi.class, // 主要是引入相关的 API 服务
PermissionApi.class})
-public class YudaoSecurityFeignAutoConfiguration {
+public class YudaoSecurityRpcAutoConfiguration {
+
+ @Bean
+ public LoginUserRequestInterceptor loginUserRequestInterceptor() {
+ return new LoginUserRequestInterceptor();
+ }
+
}
diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/rpc/LoginUserRequestInterceptor.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/rpc/LoginUserRequestInterceptor.java
new file mode 100644
index 000000000..f855a17ca
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/rpc/LoginUserRequestInterceptor.java
@@ -0,0 +1,19 @@
+package cn.iocoder.yudao.framework.security.core.rpc;
+
+import cn.iocoder.yudao.framework.rpc.core.util.FeignUtils;
+import cn.iocoder.yudao.framework.security.core.LoginUser;
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
+import feign.RequestInterceptor;
+import feign.RequestTemplate;
+
+public class LoginUserRequestInterceptor implements RequestInterceptor {
+
+ @Override
+ public void apply(RequestTemplate requestTemplate) {
+ LoginUser user = SecurityFrameworkUtils.getLoginUser();
+ if (user != null) {
+ FeignUtils.createJsonHeader(requestTemplate, SecurityFrameworkUtils.LOGIN_USER_HEADER, user);
+ }
+ }
+
+}
diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring.factories
index f7b6a72b4..3900197d5 100644
--- a/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring.factories
+++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/resources/META-INF/spring.factories
@@ -1,4 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- cn.iocoder.yudao.framework.security.config.YudaoSecurityFeignAutoConfiguration,\
+ cn.iocoder.yudao.framework.security.config.YudaoSecurityRpcAutoConfiguration,\
cn.iocoder.yudao.framework.security.config.YudaoSecurityAutoConfiguration,\
cn.iocoder.yudao.framework.security.config.YudaoWebSecurityConfigurerAdapter
diff --git a/yudao-gateway/pom.xml b/yudao-gateway/pom.xml
index 67db7b556..50f5155fe 100644
--- a/yudao-gateway/pom.xml
+++ b/yudao-gateway/pom.xml
@@ -37,15 +37,10 @@
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc
-
-
-
-
-
com.alibaba.cloud
diff --git a/yudao-gateway/src/main/resources/application.yaml b/yudao-gateway/src/main/resources/application.yaml
index bc772e6f4..59b5db671 100644
--- a/yudao-gateway/src/main/resources/application.yaml
+++ b/yudao-gateway/src/main/resources/application.yaml
@@ -1,4 +1,7 @@
spring:
+ main:
+ allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
+
cloud:
# Spring Cloud Gateway 配置项,对应 GatewayProperties 类
gateway:
diff --git a/yudao-module-infra/yudao-module-infra-biz/pom.xml b/yudao-module-infra/yudao-module-infra-biz/pom.xml
index 6b962b41a..023b13b2b 100644
--- a/yudao-module-infra/yudao-module-infra-biz/pom.xml
+++ b/yudao-module-infra/yudao-module-infra-biz/pom.xml
@@ -66,13 +66,8 @@
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-dubbo
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc
diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml
index d2964b46b..de52bf4f9 100644
--- a/yudao-module-system/yudao-module-system-biz/pom.xml
+++ b/yudao-module-system/yudao-module-system-biz/pom.xml
@@ -81,13 +81,8 @@
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-dubbo
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc