使用内部Feign,出现[com.mydao.tourist.base.BaseResult<java.util.List<com.mydao.tourist.fegin.dto.ESGroupSql

异常描述:

org.springframework.web.client.RestClientException: Error while extracting response for type [com.mydao.tourist.base.BaseResult<java.util.List<com.mydao.tourist.fegin.dto.ESGroupSqlRespVo>>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize instance of `java.util.ArrayList<com.mydao.tourist.fegin.dto.ESGroupSqlRespVo>` out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<com.mydao.tourist.fegin.dto.ESGroupSqlRespVo>` out of VALUE_STRING token
 at [Source: (PushbackInputStream); line: 1, column: 73] (through reference chain: com.mydao.tourist.base.BaseResult["data"])

控制台 异常:

 
 DynamicServerListLoadBalancer for client ticketing-elastic-statistics-main initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=ticketing-elastic-statistics-main,current list of Servers=[192.168.1.236:7611],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;    Instance count:1;    Active connections count: 0;    Circuit breaker tripped count: 0;    Active connections per server: 0.0;]
},Server stats: [[Server:192.168.1.236:7611;    Zone:defaultZone;    Total Requests:0;    Successive connection failure:0;    Total blackout seconds:0;    Last connection made:Thu Jan 01 08:00:00 CST 1970;    First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;    total failure count in last (1000) msecs:0;    average resp time:0.0;    90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;    max resp time:0.0;    stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@2383f259
2023-07-11 16:00:34 |INFO | com.netflix.config.ChainedDynamicProperty [115] | Flipping property: ticketing-elastic-statistics-main.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

Feign

xxxxx:  代指接口服务名     跟此异常无关

APIUrl:代指接口地址     跟此异常无关

加上 红色字体的 部分即可解决 ;

consumes = "application/json; charset=UTF-8", produces = "application/json; charset=UTF-8"

/**
* @Author wzq
* @Version 1.0
* @Description //TODO ES统计中心 API
* @Date 2023/6/26
**/
@FeignClient(name = "xxxxx", configuration = FeignTokenInterceptor.class)
public interface EsStatisticsService {

/**
* ES统计的【FeignAPI】
* todo 统计数据API
* */
@PostMapping(value = "APIUrl", consumes = "application/json; charset=UTF-8", produces = "application/json; charset=UTF-8")
@ApiOperation(value = "统计数据API", notes = "统计数据API", httpMethod = "POST")
BaseResult<List<ESGroupSqlRespVo>> categoryStatisticsDataAPI(@RequestBody CategoryStatisticsDataReqVo categoryStatisticsDataReqVo);



}

<think>好的,我现在需要解决用户遇到的Feign错误:java.lang.UnsupportedOperationException: No fallback available。用户提到已经尝试设置feign.hystrix.enabled为false,但问题依旧存在。我需要先理解这个错误的原因,然后找到解决方案。 首先,我记得Feign整合Hystrix时,如果启用了熔断机制,当远程调用失败且没有定义fallback方法,就会抛出这个错误。用户可能没有正确配置fallback类,或者在@FeignClient注解中没有指定fallback属性。另外,检查是否在配置文件中启用了Hystrix,可能用户虽然禁用了Hystrix,但某些配置可能冲突。 接下来,根据用户提供的引用内容,引用[3]提到需要在@FeignClient中添加fallback类,并且编写相应的Fallback文件。引用[4]指出用户可能错误地配置了feign.hystrix.enabled为false,这可能导致Hystrix未被正确启用,从而无法触发fallback。需要确认是否确实需要禁用Hystrix,或者是否配置有误。 可能的解决步骤包括: 1. 确保在@FeignClient注解中正确指定fallback类。 2. 检查fallback类是否实现了Feign客户端接口,并且所有方法都有实现。 3. 确认Hystrix的配置是否正确,比如是否需要在配置文件中启用Hystrix。 4. 如果用户不想使用Hystrix,可能需要彻底禁用相关配置,避免冲突。 此外,用户可能没有正确地将fallback类注册为Spring Bean,或者fallback类中存在错误导致无法实例化。需要检查这些方面,并提供具体的代码示例帮助用户解决问题。</think>### Feign出现No fallback available错误的解决方案 #### 1. 检查@FeignClient注解配置 确保在Feign客户端接口的`@FeignClient`注解中明确指定`fallback`类。这是触发熔断机制的关键配置: ```java @FeignClient( name = "service-name", url = "${service.url}", fallback = MyFallback.class // 必须声明fallback类 ) public interface MyFeignClient { @GetMapping("/endpoint") String callEndpoint(); } ``` 若未声明`fallback`属性,系统会抛出`No fallback available`异常[^3]。 #### 2. 验证Fallback类实现 Fallback类必须满足以下条件: - 实现Feign客户端接口 - 被声明为`@Component`或`@Service` - 包含无参构造器 ```java @Component // 必须注册为Spring Bean public class MyFallback implements MyFeignClient { @Override public String callEndpoint() { return "fallback response"; } } ``` 若Fallback类未被Spring容器管理,或未实现接口方法,都会导致错误[^3]。 #### 3. 检查Hystrix配置状态 根据异常类型选择配置策略: - **需要熔断功能**时: ```yaml feign: hystrix: enabled: true # 必须启用Hystrix hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 5000 ``` - **不需要熔断功能**时: ```yaml feign: hystrix: enabled: false # 彻底禁用Hystrix ``` #### 4. 验证依赖完整性 检查pom.xml必须包含以下依赖: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> ``` #### 5. 调试Fallback初始化 在应用启动时添加JVM参数检测Bean加载: ```bash -Dlogging.level.org.springframework.beans.factory=DEBUG ``` 控制台应输出类似日志: ``` Creating instance of bean 'MyFallback' Finished creating instance of bean 'MyFallback' ``` #### 6. 完整配置示例 ```yaml feign: client: config: default: connectTimeout: 3000 readTimeout: 5000 hystrix: enabled: true # 熔断开关 hystrix: command: default: execution: timeout: enabled: true isolation: thread: timeoutInMilliseconds: 8000 ``` ### 常见错误场景分析 | 错误现象 | 根本原因 | 解决方案 | |---------|---------|---------| | `NoSuchBeanDefinitionException` | Fallback类未注册为Bean | 添加@Component注解 | | `AbstractMethodError` | Fallback类未实现接口方法 | 实现所有声明的方法 | | `FeignTimeoutException` | 未正确配置超时参数 | 调整hystrix/feign超时设置 | 若按照上述步骤配置后仍出现错误,建议使用`@EnableHystrix`注解显式启用熔断功能: ```java @SpringBootApplication @EnableFeignClients @EnableHystrix // 强制启用Hystrix public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值