alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.18k stars 7.96k forks source link

sentinel 1.8.6 导致openfeign接口出现Caused by: java.lang.IllegalStateException: No fallback instance of type #2975

Open zhl19911203 opened 1 year ago

zhl19911203 commented 1 year ago

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

当设置feign.sentinel.enabled: true时出现如下错误

Caused by: java.lang.IllegalStateException: No fallback instance of type class com.fosafer.voiceprint.platform.module.infra.api.logger.ApiErrorLogApiFallback found for feign client infra-server at com.alibaba.cloud.sentinel.feign.SentinelFeign$Builder$1.getFromContext(SentinelFeign.java:125) at com.alibaba.cloud.sentinel.feign.SentinelFeign$Builder$1.create(SentinelFeign.java:104) at org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory.create(FeignCachingInvocationHandlerFactory.java:50) at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:64) at feign.Feign$Builder.target(Feign.java:268) at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30) at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:379) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:427) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:402) at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:235) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ... 91 common frames omitted

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

代码如下

@FeignClient(name = ApiConstants.NAME,fallback = ApiErrorLogApiFallback.class) public interface ApiErrorLogApi {

@PostMapping(ApiConstants.PREFIX + "/infra/api-error-log/create")
CommonResult<Boolean> createApiErrorLog(@Valid @RequestBody ApiErrorLogCreateReqDTO createDTO);

}

@Component public class ApiErrorLogApiFallback implements ApiErrorLogApi { @Override public CommonResult createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) { return CommonResult.timeout(); } }

Tell us your environment

    <spring.boot.version>2.6.13</spring.boot.version>
    <spring.cloud.version>2021.0.1</spring.cloud.version>
    <spring.cloud.alibaba.version>2021.0.1.0</spring.cloud.alibaba.version>

Anything else we need to know?

ningqixiao commented 2 months ago

没有扫描到fallback,在远程调用的启动类上@SpringBootApplication(scanBasePackages = "你的fallba的包名")就可以解决该问题,