抽象方法错误:com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidatateMetadata解决办法
Sentinel
alibaba/Sentinel: Sentinel 是阿里巴巴开源的一款面向分布式服务架构的流量控制、熔断降级组件,提供实时监控、限流、降级和系统保护功能,适用于微服务治理场景。
项目地址:https://gitcode.com/gh_mirrors/sentine/Sentinel
·
SpringCloud Alibaba Sentinel整合SpringCloud OpenFeign,启动报错
FactoryBean threw exception on object creation; nested exception is java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidatateMetadata(Ljava/lang/Class;)Ljava/util/List;
报错原因:
Sentinel框架SentinelContractHolder类中找不到parseAndValidatateMetadata这个方法,是因为这个方法拼写有错误,在Sentinel和OpenFeign新版本中已经修正为parseAndValidateMetadata
| 版本 | 方法名 |
|---|---|
| < 2.2.1.RELEASE | parseAndValidatateMetadata |
| >= 2.2.2.RELEASE | parseAndValidateMetadata |
Sentinel(2.2.1.RELEASE)中的SentinelContractHolder类调用的是新版本的OpenFeign(2.2.2.RELEASE)方法
而Spring Cloud Alibaba(2.2.1.RELEASE)引入的是旧版本的OpenFeign(2.2.1.RELEASE)方法
解决方法
- 解决版本差异问题
- 覆盖SentinelContractHolder类,使其继续调用旧版parseAndValidatateMetadata方法
在项目模块中新建包:com.alibaba.cloud.sentinel.feign
然后添加如下类:package com.alibaba.cloud.sentinel.feign; import feign.Contract; import feign.MethodMetadata; import java.util.HashMap; import java.util.List; import java.util.Map; public class SentinelContractHolder implements Contract { private final Contract delegate; /** * map key is constructed by ClassFullName + configKey. configKey is constructed by {@link * feign.Feign#configKey} */ public final static Map<String, MethodMetadata> METADATA_MAP = new HashMap<>(); public SentinelContractHolder(Contract delegate) { this.delegate = delegate; } @Override public List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) { List<MethodMetadata> metadatas = delegate.parseAndValidatateMetadata(targetType); metadatas.forEach(metadata -> METADATA_MAP .put(targetType.getName() + metadata.configKey(), metadata)); return metadatas; } }
推荐使用第二种方法,maven依赖一直是一个复杂的问题,轻易不要变动版本,否则可能牵一发而动全身,带来无法预料的潜在影响。
alibaba/Sentinel: Sentinel 是阿里巴巴开源的一款面向分布式服务架构的流量控制、熔断降级组件,提供实时监控、限流、降级和系统保护功能,适用于微服务治理场景。
最近提交(Master分支:2 个月前 )
a08dc695
* Fix the bugs mentioned in issue #3562 and #3563.
Fix the issue in the spring-webmvc-v6x-adapter where, after configuring http-method-specify:true, the prefixes for different request methods were not concatenated.
Fix incorrect time unit in the tooltip when adding a new circuit breaker rule with statistical window duration.
* Fix the bugs mentioned in issue #3562 and #3563.
Fix the issue in the spring-webmvc-v6x-adapter where, after configuring http-method-specify:true, the prefixes for different request methods were not concatenated.
Fix incorrect time unit in the tooltip when adding a new circuit breaker rule with statistical window duration.
* Fixed the issue where the original test class was affected by the concatenation of resource names after adding the logic for the HTTP prefix concatenation.
* remove mseHttpMethodSpecify field and update the unit test as suggested.
* retrigger CI 12 天前
e60f0d0e
* Simple rules should have higher priority than regular expression rules
* Add optional switch to skip regex matching when simple rules already match, default: false, keeps backward compatibility.
* fix RuleManagerTest unit test failure 12 天前
新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐

所有评论(0)