From e50fb137e7ed00bc7c69366ce33969172dd961f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Sat, 11 May 2024 12:38:11 +0800 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=20=E5=9B=9E=E6=BB=9Afeign=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=99=8D=E7=BA=A7=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/common/sentinel/PigxSentinelAutoConfiguration.java | 2 +- .../common/sentinel/feign/PigxSentinelInvocationHandler.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java index 6bf549674..5913648e5 100755 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java @@ -46,7 +46,7 @@ public class PigxSentinelAutoConfiguration { @Bean @Scope("prototype") @ConditionalOnMissingBean - @ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled") + @ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled",matchIfMissing = true) public Feign.Builder feignSentinelBuilder() { return PigxSentinelFeign.builder(); } diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/feign/PigxSentinelInvocationHandler.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/feign/PigxSentinelInvocationHandler.java index 8926d35ec..9ee305bbd 100644 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/feign/PigxSentinelInvocationHandler.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/feign/PigxSentinelInvocationHandler.java @@ -8,6 +8,7 @@ import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.slots.block.BlockException; +import com.pig4cloud.pigx.common.core.util.R; import feign.Feign; import feign.InvocationHandlerFactory; import feign.MethodMetadata; @@ -118,6 +119,10 @@ public class PigxSentinelInvocationHandler implements InvocationHandler { throw new AssertionError(e.getCause()); } } + else if (R.class == method.getReturnType()) { + log.error("feign 服务间调用异常", ex); + return R.failed(ex.getLocalizedMessage()); + } else { throw ex; }