Spring Cloud使用Sentinel做为Feign的熔断器之Fallback统一处理

参考博客:https://blog.csdn.net/ttzommed/article/details/90669320


原文中编写FunSentinelFeign类时,由于SentinelInvocationHandler方法的构造函数并不是public修饰
在这里插入图片描述
return new SentinelInvocationHandler(target, dispatch, funFallbackFactory),会报错。修改为使用反射调用

//获取指定的构造方法
                    Constructor<SentinelInvocationHandler> constructor = SentinelInvocationHandler.class.
                            getDeclaredConstructor(Target.class, Map.class, FallbackFactory.class);
                    constructor.setAccessible(true);
 return constructor.newInstance(target, dispatch, new FallbackFactory.Default(fallbackInstance));

demo地址:gitee

你可能感兴趣的:(springCloud)