Tag Archives: springcloud-alibaba

java.lang.AbstractMethodError: Receiver class com.alibaba.cloud.sentinel.feign.SentinelContractHolde

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!