Sentinel icon indicating copy to clipboard operation
Sentinel copied to clipboard

Sentinel 和 Feign 集成时,方法名称写错

Open dsaewq321 opened this issue 6 years ago • 13 comments

版本:spring-cloud-alibaba-2.1.0.RELEASE

Sentinel 和 Feign 集成时,方法名称写错,有如下接口: List<MethodMetadata> feign.Contract.parseAndValidateMetadata(Class<?> targetType);

在 spring-cloud-alibaba-sentinel-2.1.0.RELEASE.jar 中,实现了上述方法,不过方法名却写错了,导致目前无法使用,实现方法如下: List<MethodMetadata> com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidatateMetadata(Class<?> targetType);

dsaewq321 avatar Mar 18 '20 14:03 dsaewq321

Could you please provide the detailed error message?

sczyh30 avatar Mar 18 '20 14:03 sczyh30

当我在集成 Sentinel 和 Feign 时,运行github上的示例代码,代码地址如下: https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java

遇到了类似于上述的问题,具体问题日志如下: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'echoController': Unsatisfied dependency expressed through field 'echoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.jmlee.hello.sentinel.feign.service.EchoService': FactoryBean threw exception on object creation; nested exception is java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidateMetadata(Ljava/lang/Class;)Ljava/util/List;

所用版本:

Spring Cloud Version:Hoxton.SR3 Spring Cloud Alibaba Version:2.2.0.RELEASE

carCV avatar Mar 18 '20 14:03 carCV

@fangjian0423 Could you please take a look?

sczyh30 avatar Mar 18 '20 15:03 sczyh30

Hoxton.SR1 中,fegin.context接口的定义为parseAndValidatateMetadata Hoxton.SR3 中,fegin.context接口的定义为parseAndValidateMetadata。就是之前版本中定义的方法名拼写错误,所以在Hoxton.SR1后面的版本更正过来,所以出现Caused by: java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidateMetadata(Ljava/lang/Class;)Ljava/util/List;错误。

我目前的解决办法是:在工程合适的地方,新建包com.alibaba.cloud.sentinel.feign。重新修改一下SentinelContractHolder即可

` 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;
}

} `

herodotus-ecosystem avatar Mar 20 '20 06:03 herodotus-ecosystem

By reproducing it, I found two ways to solve this:

  1. Change Spring Cloud Version from Hoxton.SR3 to Hoxton.RELEASE

  2. Remain using Hoxton.SR3, and specified the version of spring-cloud-openfeign-dependencies to 2.2.0.RELEASE.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-dependencies</artifactId>
            <version>2.2.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Note that the spring-cloud-openfeign-dependencies should be in front of spring-cloud-dependencies.

The reason is as @Pointerv described.

cdfive avatar Mar 20 '20 16:03 cdfive

对,我目前也是这样解决的。thanks.  

半缘 忘忧 [email protected]

exgwbvdtcfqpbgce

 

------------------ 原始邮件 ------------------ 发件人: "Felix"<[email protected]>; 发送时间: 2020年3月20日(星期五) 下午2:26 收件人: "alibaba/Sentinel"<[email protected]>; 抄送: "半缘 忘忧"<[email protected]>; "Author"<[email protected]>; 主题: Re: [alibaba/Sentinel] Sentinel 和 Feign 集成时,方法名称写错 (#1345)

Hoxton.SR1 中,fegin.context接口的定义为parseAndValidatateMetadata Hoxton.SR3 中,fegin.context接口的定义为parseAndValidateMetadata。就是之前版本中定义的方法名拼写错误,所以在Hoxton.SR1后面的版本更正过来,所以出现Caused by: java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidateMetadata(Ljava/lang/Class;)Ljava/util/List;错误。

我目前的解决办法是:在工程合适的地方,新建包com.alibaba.cloud.sentinel.feign。重新修改一下SentinelContractHolder即可 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&gt; METADATA_MAP = new HashMap<&gt;(); public SentinelContractHolder(Contract delegate) { this.delegate = delegate; } @Override public List<MethodMetadata&gt; parseAndValidateMetadata(Class<?&gt; targetType) { List<MethodMetadata&gt; metadatas = delegate.parseAndValidateMetadata(targetType); metadatas.forEach(metadata -&gt; METADATA_MAP .put(targetType.getName() + metadata.configKey(), metadata)); return metadatas; } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

dsaewq321 avatar Mar 21 '20 01:03 dsaewq321

good idea, thank u   

半缘 忘忧 [email protected]

exgwbvdtcfqpbgce

 

------------------ 原始邮件 ------------------ 发件人: "cdfive"<[email protected]>; 发送时间: 2020年3月21日(星期六) 凌晨0:15 收件人: "alibaba/Sentinel"<[email protected]>; 抄送: "半缘 忘忧"<[email protected]>; "Author"<[email protected]>; 主题: Re: [alibaba/Sentinel] Sentinel 和 Feign 集成时,方法名称写错 (#1345)

By reproducing it, I found two ways to solve this:

Change Spring Cloud Version from Hoxton.SR3 to Hoxton.RELEASE

Remain using Hoxton.SR3, and specified the version of spring-cloud-openfeign-dependencies

<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-openfeign-dependencies</artifactId> <version>${spring-cloud-openfeign.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR3</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.2.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

Note that the spring-cloud-openfeign-dependencies should be in front of spring-cloud-dependencies.

The reason is as @Pointerv described.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

dsaewq321 avatar Mar 21 '20 01:03 dsaewq321

碰到了相同的问题,谢谢

fanqisoft avatar Mar 24 '20 10:03 fanqisoft

碰到了同样的问题,多谢

stalary avatar Mar 24 '20 15:03 stalary

Spring Cloud Alibaba 2.2.0.RELEASE based on Hoxton.RELEASE.

Spring Cloud Alibaba 2.2.1.RELEASE based on Hoxton.SR3 and it's going to release soon.

fangjian0423 avatar Mar 25 '20 02:03 fangjian0423

Closing this issue as SCA 2.2.1.RELEASE has been released. Thanks all :)

sczyh30 avatar Apr 17 '20 09:04 sczyh30

Caused by: java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidatateMetadata(Ljava/lang/Class;)Ljava/util/List; at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154) ~[feign-core-10.4.0.jar:na] at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52) ~[feign-core-10.4.0.jar:na] at feign.Feign$Builder.target(Feign.java:251) ~[feign-core-10.4.0.jar:na] at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:38) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:243) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:272) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:252) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] ... 48 common frames omitted

Caused by: java.lang.AbstractMethodError: com.alibaba.cloud.sentinel.feign.SentinelContractHolder.parseAndValidatateMetadata(Ljava/lang/Class;)Ljava/util/List; at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154) ~[feign-core-10.4.0.jar:na] at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52) ~[feign-core-10.4.0.jar:na] at feign.Feign$Builder.target(Feign.java:251) ~[feign-core-10.4.0.jar:na] at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:38) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:243) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:272) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:252) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] ... 48 common frames omitted

MemoryF avatar May 13 '20 16:05 MemoryF

2.2.1.RELEASE Hoxton.SR3 可以适配了。但是要去中央仓库下载Hoxton.SR3 阿里云仓库还没有

MemoryF avatar May 13 '20 17:05 MemoryF