Caused by: java.lang.AbstractMethodError: Receiver class com.alibaba.cloud.sentinel.feign.SentinelContractHolder does not define or inherit an implementation of the resolved method abstract parseAndValidatateMetadata(Ljava/lang/Class;) Ljava/util/List; of interface feign.Contract.
When doing openfeign for sentinel service, I encountered the following errors:
according to the source code tracing, I found that there was a problem with the implementation class of feign’s contract interface. In my project springcloud, Sr1 version h, depends on the following:
the reason for the problem is that the version is inconsistent. For feign’s contract interface, 2.2.1 and 2.2.2 are different
2.2.1.RELEASE:
// TODO: break this and correct spelling at some point
List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType);
2.2.2.RELEASE:
List<MethodMetadata> parseAndValidateMetadata(Class<?> targetType);
In 2.2.1.release, there is a line of comment description. The spelling of interface method name is wrong. In 2.2.2.release, the method name has been corrected, that is, the method name has changed
the sentinelcontractholder class in spring cloud Alibaba sentinel uses this method of the interface (feign 2.2.1. Release version)
```java
@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;
}
After finding out the reason, modify the implementation class of contract interface of feign. Create a package of com.alibaba.cloud.sentinel.feign in the appropriate place of the project. Modify the implementation class sentinelcontractholder as follows:
/**
* @author geng
* @create 2021/4/30 -- 10:47
*/
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<?> targetType) {
List<MethodMetadata> metadatas = delegate.parseAndValidateMetadata(targetType);
metadatas.forEach(metadata -> METADATA_MAP
.put(targetType.getName() + metadata.configKey(), metadata));
return metadatas;
}
}
Run again, start successfully!
Read More:
- java.lang.AbstractMethodError:com.mysql.jdbc.Connection.isValid(I)Z
- Caused by: java.lang.ClassNotFoundException: com.alibaba.nacos.api.naming.NamingMaintainService
- java.lang.IllegalArgumentException: Receiver not registered:
- [unity] Android package error java.lang.ClassNotFoundException Did not find class com.unity3d . player.MainActivity
- How to mine Bitcoin using Alibaba Cloud and Tencent Cloud servers (ubuntu)
- java.lang.IllegalStateException : unable to read meta data for class
- Idea error: (4, 28) Java: package com.alibaba.fastjson does not exist
- Spring cloud Alibaba 2020.0.rc1 does not integrate ribbon error reporting unknownhostexception
- Remember a feign error: feign.FeignException : status 404 reading XXXClient#XXMethod(Long)
- Alibaba cloud ECS curl error 6
- com.alibaba.fastjson .JSONException: For input string: “3000-01-01” or “9999-12-31”
- java.lang.Throwable: Substituted for the exception com.bea.xml.SchemaTypeLoaderException which lack
- Alibaba cloud builds FTP server 200 port command successful. Consider using PASV. 425 failed to establish connection
- Meven report error java.lang.NoSuchMethodError : com.google.common . base.Preconditions.checkArgument
- java.lang.NoSuchMethodError Quote: javax.servlet.com Yeah. HttpServletRequest.isAsyncStarted ()Z
- There is no getter for property named ‘id‘ in ‘class java.lang.Integer‘
- Method threw ‘java.lang.NullPointerException‘ exception. Cannot evaluate com.sun.proxy.xxx
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- Error in idea compilation: java.lang.OutOfMemoryError Java heap space and java.lang.StackOverflowError
- Mybatis error,There is no getter for property named ‘xx’ in ‘class java.lang.String The solution