Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dsaewq321 opened this issue Mar 18, 2020 · 13 comments
Closed

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

dsaewq321 opened this issue Mar 18, 2020 · 13 comments
Labels
integration/spring-cloud Issue related to Spring Cloud Alibaba integration

Comments

@dsaewq321
Copy link

版本: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);

@sczyh30 sczyh30 added the integration/spring-cloud Issue related to Spring Cloud Alibaba integration label Mar 18, 2020
@sczyh30
Copy link
Member

sczyh30 commented Mar 18, 2020

Could you please provide the detailed error message?

@carCV
Copy link

carCV commented Mar 18, 2020

当我在集成 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

@sczyh30
Copy link
Member

sczyh30 commented Mar 18, 2020

@fangjian0423 Could you please take a look?

@herodotus-ecosystem
Copy link

herodotus-ecosystem commented Mar 20, 2020

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

}
`

@cdfive
Copy link
Collaborator

cdfive commented Mar 20, 2020

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.

@dsaewq321
Copy link
Author

dsaewq321 commented Mar 21, 2020 via email

@dsaewq321
Copy link
Author

dsaewq321 commented Mar 21, 2020 via email

@fanqisoft
Copy link

碰到了相同的问题,谢谢

@stalary
Copy link

stalary commented Mar 24, 2020

碰到了同样的问题,多谢

@fangjian0423
Copy link
Contributor

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.

@sczyh30
Copy link
Member

sczyh30 commented Apr 17, 2020

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

@sczyh30 sczyh30 closed this as completed Apr 17, 2020
@MemoryF
Copy link

MemoryF commented May 13, 2020

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
Copy link

MemoryF commented May 13, 2020

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

CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
* Remove the useless files

* Replace PermSize with MetaspaceSize, details see http://openjdk.java.net/jeps/122

* Update DLedgerCommitLog.java (alibaba#1145)

Delete useless code

* Remove the duplicate content

* Polish the comment (alibaba#1107)

* Minor Typo fix  (alibaba#860)

* [ISSUE alibaba#1082] Fix disconnection of HA (alibaba#1083)

* fixed the text description in chinese doc (alibaba#1339)

* fix /dev/shm not found on some OSs (alibaba#1345)

* Refactor the protection logic when pulling

* change the MQVersion variable to rocketmq 4.5.2 version;

* Minor polish

* Fix the wrong package name

* [maven-release-plugin] prepare release rocketmq-all-4.5.2

* [maven-release-plugin] prepare for next development iteration

* [RIP-15]Add Ipv6 support for RocketMQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration/spring-cloud Issue related to Spring Cloud Alibaba integration
Projects
None yet
Development

No branches or pull requests

9 participants