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

kd3sttzy  于 4个月前  发布在  Java
关注(0)|答案(1)|浏览(164)

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?

bcs8qyzn

bcs8qyzn1#

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

相关问题