Procházet zdrojové kódy

fix OpenFeign参数配置

Eric před 1 rokem
rodič
revize
c3e16728dc

+ 2 - 3
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/AdminFeignService.java

@@ -8,7 +8,6 @@ import com.yonge.cooleshow.api.feign.dto.TeacherApi;
 import com.yonge.cooleshow.api.feign.dto.TenantWrapper;
 import com.yonge.cooleshow.api.feign.dto.UserFriendInfoVO;
 import com.yonge.cooleshow.api.feign.fallback.AdminFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.cooleshow.common.entity.ContractDto;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.common.entity.MallOrderItemDto;
@@ -29,8 +28,8 @@ import java.util.List;
  * @author liujunchi
  * @date 2022-05-06
  */
-@FeignClient(name = AppConstant.APPLICATION_ADMIN + AppConstant.SERVER, configuration = FeignConfiguration.class,
-        fallback = AdminFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.admin-server.name:admin-server}", url = "${app-config.open-feign.admin-server.url:}",
+        configuration = FeignConfiguration.class, fallback = AdminFeignServiceFallback.class)
 public interface AdminFeignService {
     /***
      * 轮询用户订单

+ 3 - 3
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/CmsFeignService.java

@@ -1,8 +1,7 @@
 package com.yonge.cooleshow.api.feign;
 
-import com.yonge.cooleshow.common.constant.AppConstant;
-import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.api.feign.fallback.CmsFeignServiceFallback;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -14,7 +13,8 @@ import org.springframework.web.bind.annotation.GetMapping;
  * @date 2022-04-29
  */
 
-@FeignClient(name = AppConstant.APPLICATION_CMS + AppConstant.SERVER, configuration = FeignConfiguration.class, fallback = CmsFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.cms-server.name:cms-server}", url = "${app-config.open-feign.cms-server.url:}",
+        configuration = FeignConfiguration.class, fallback = CmsFeignServiceFallback.class)
 public interface CmsFeignService {
 
     /**

+ 2 - 4
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallAdminFeignService.java

@@ -1,19 +1,17 @@
 package com.yonge.cooleshow.api.feign;
 
 import com.yonge.cooleshow.api.feign.fallback.MallAdminFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.ResponseBody;
 
 import java.util.List;
 import java.util.Map;
 
-@FeignClient(name = AppConstant.APPLICATION_MALL_ADMIN + AppConstant.SERVER, configuration = FeignConfiguration.class,
-        fallback = MallAdminFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.mall-admin-server.name:mall-admin-server}", url = "${app-config.open-feign.mall-admin-server.url:}",
+        configuration = FeignConfiguration.class, fallback = MallAdminFeignServiceFallback.class)
 public interface MallAdminFeignService {
 
 

+ 2 - 3
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallPortalFeignService.java

@@ -1,14 +1,13 @@
 package com.yonge.cooleshow.api.feign;
 
 import com.yonge.cooleshow.api.feign.fallback.MallPortalFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 
-@FeignClient(name = AppConstant.APPLICATION_MALL_PORTAL + AppConstant.SERVER, configuration = FeignConfiguration.class,
-        fallback = MallPortalFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.mall-portal-server.name:mall-portal-server}", url = "${app-config.open-feign.mall-portal-server.url:}",
+        configuration = FeignConfiguration.class, fallback = MallPortalFeignServiceFallback.class)
 public interface MallPortalFeignService {
 
     /**

+ 2 - 5
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/StudentFeignService.java

@@ -1,16 +1,13 @@
 package com.yonge.cooleshow.api.feign;
 
-import com.yonge.cooleshow.api.feign.dto.StudentWrapper;
 import com.yonge.cooleshow.api.feign.fallback.StudentFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 
-@FeignClient(name = AppConstant.APPLICATION_STUDENT + AppConstant.SERVER, configuration = FeignConfiguration.class, fallback = StudentFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.student-server.name:student-server}", url = "${app-config.open-feign.student-server.url:}",
+        configuration = FeignConfiguration.class, fallback = StudentFeignServiceFallback.class)
 public interface StudentFeignService {
 
     /***

+ 2 - 2
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/TeacherFeignService.java

@@ -1,14 +1,14 @@
 package com.yonge.cooleshow.api.feign;
 
 import com.yonge.cooleshow.api.feign.fallback.TeacherFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 
-@FeignClient(name = AppConstant.APPLICATION_TEACHER + AppConstant.SERVER, configuration = FeignConfiguration.class, fallback = TeacherFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.teacher-server.name:teacher-server}", url = "${app-config.open-feign.teacher-server.url:}",
+        configuration = FeignConfiguration.class, fallback = TeacherFeignServiceFallback.class)
 public interface TeacherFeignService {
 
     /***

+ 2 - 3
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/TenantFeignService.java

@@ -1,13 +1,12 @@
 package com.yonge.cooleshow.api.feign;
 
 import com.yonge.cooleshow.api.feign.fallback.AdminFeignServiceFallback;
-import com.yonge.cooleshow.common.constant.AppConstant;
 import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 
-@FeignClient(name = AppConstant.APPLICATION_TENANT + AppConstant.SERVER, configuration = FeignConfiguration.class,
-        fallback = AdminFeignServiceFallback.class)
+@FeignClient(name = "${app-config.open-feign.tenant-server.name:tenant-server}", url="${app-config.open-feign.tenant-server.url:}",
+        configuration = FeignConfiguration.class, fallback = AdminFeignServiceFallback.class)
 public interface TenantFeignService {
 
     //机构人员汇总

+ 56 - 0
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/properties/OpenFeignConfigProperties.java

@@ -0,0 +1,56 @@
+package com.yonge.cooleshow.api.feign.properties;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.Serializable;
+
+/**
+ * OpenFeign配置
+ * Created by Eric.Shang on 2023/2/8.
+ */
+@ConfigurationProperties(prefix = "app-config.open-feign")
+@Configuration
+@Data
+public class OpenFeignConfigProperties {
+
+    @ApiModelProperty("内容管理服务")
+    @NestedConfigurationProperty
+    private ServerConfig cmsServer;
+
+    @ApiModelProperty("后台管理服务")
+    @NestedConfigurationProperty
+    private ServerConfig adminServer;
+
+    @ApiModelProperty("商城后台服务")
+    @NestedConfigurationProperty
+    private ServerConfig mallAdminServer;
+
+    @ApiModelProperty("商城服务")
+    @NestedConfigurationProperty
+    private ServerConfig mallPortalServer;
+
+    @ApiModelProperty("学生服务")
+    @NestedConfigurationProperty
+    private ServerConfig studentServer;
+
+    @ApiModelProperty("老师服务")
+    @NestedConfigurationProperty
+    private ServerConfig teacherServer;
+
+    @ApiModelProperty("机构服务")
+    @NestedConfigurationProperty
+    private ServerConfig tenantServer;
+
+    @Data
+    @ApiModel("OpenFeign服务配置")
+    public static class ServerConfig implements Serializable {
+
+        private String name;
+        private String url;
+    }
+}

+ 23 - 1
cooleshow-app/src/test/resources/application.yml

@@ -7,4 +7,26 @@ app-config:
     student: api-student
     classroom: api-classroom
     website: api-website
-    tenant: api-tenant
+    tenant: api-tenant
+  open-feign:
+    admin-server:
+      name: admin-server
+      url: https://test.colexiu.com/api-admin
+    cms-server:
+      name: cms-server
+      url: https://test.colexiu.com/api-cms
+    mall-admin-server:
+      name: mall-admin-server
+      url: https://test.colexiu.com/api-mall-admin
+    mall-portal-server:
+      name: mall-portal-server
+      url: https://test.colexiu.com/api-mall-portal
+    student-server:
+      name: student-server
+      url: https://test.colexiu.com/api-student
+    teacher-server:
+      name: teacher-server
+      url: https://test.colexiu.com/api-teacher
+    tenant-server:
+      name: tenant-server
+      url: https://test.colexiu.com/api-tenant