在整合sentinel和服务的时候,报标题这个错,也是由版本原因导致的
feign的Contract接口,
2.2.0.RELEASE:
// TODO: break this and correct spelling at some point
List parseAndValidatateMetadata(Class> targetType);
2.2.2.RELEASE:
List parseAndValidateMetadata(Class> targetType);
在2.2.0.RELEASE里有一行注释描述,接口方法名拼写错误,在2.2.2.RELEASE方法已修正了,即方法名发生了改变。
在spring-cloud-alibaba-sentinel中的SentinelContractHolder类,用到了该接口的这个方法(feign2.2.0.RELEASE版本):
@Override
public List parseAndValidatateMetadata(Class> targetType) {
List metadatas = delegate.parseAndValidatateMetadata(targetType);
metadatas.forEach(metadata -> METADATA_MAP
.put(targetType.getName() + metadata.configKey(), metadata));
return metadatas;
}
解决办法,要不修改版本,要不就是在工程合适的地方,新建包com.alibaba.cloud.sentinel.feign。重新修改一下SentinelContractHolder即可
/**
* @author WGR
* @create 2020/8/21 -- 0:27
*/
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 METADATA_MAP = new HashMap<>();
public SentinelContractHolder(Contract delegate) {
this.delegate = delegate;
}
@Override
public List parseAndValidateMetadata(Class> targetType) {
List metadatas = delegate.parseAndValidateMetadata(targetType);
metadatas.forEach(metadata -> METADATA_MAP
.put(targetType.getName() + metadata.configKey(), metadata));
return metadatas;
}
}