错误:
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
Sentinel(2.2.1.RELEASE)中的SentinelContractHolder类调用的是新版本的OpenFeign(2.2.2.RELEASE)方法
而Spring Cloud Alibaba(2.2.1.RELEASE)引入的是旧版本的OpenFeign(2.2.1.RELEASE)方法
解决方法:
方法一,更换Spring cloud alibaba版本或Sentinel版本
方法二,覆盖SentinelContractHolder类,使其继续调用旧版parseAndValidatateMetadata方法
- 在项目模块中新建包:com.alibaba.cloud.sentinel.feign
- 添加SentinelContractHolder类
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> parseAndValidateMetadata(Class<?> aClass) {
List<MethodMetadata> metadatas = delegate.parseAndValidateMetadata(aClass);
metadatas.forEach(metadata -> METADATA_MAP
.put(aClass.getName() + metadata.configKey(), metadata));
return metadatas;
}
}