You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot使用Feign客户端执行定时任务时出现周期性HTTP 400错误

Feign客户端周期性HTTP 400错误问题

在使用Feign客户端进行服务间通信的Spring Boot应用中,遇到了周期性错误问题,该问题出现在每分钟执行一次POST请求的定时任务中:

  • 若应用启动后第一个定时请求返回HTTP 400(Bad Request),则该会话中后续所有请求都会持续返回HTTP 400错误
  • 终止进程并重启应用后,所有请求又能成功执行,且该模式会随每次重启重复出现——启动时出错的会话会持续出错,启动时正常的会话则全程正常
  • 服务器配置未做任何变更,处理请求的逻辑保持一致

示例场景

  1. 启动应用——第一个请求返回HTTP 400
  2. 该会话中后续所有请求均返回HTTP 400
  3. 终止应用进程并重启
  4. 重启后的第一个请求执行成功
  5. 新会话中后续所有请求均成功
  6. 再次终止并重启进程,步骤1的问题重复出现

相关代码

Feign客户端定义

@FeignClient(name = "withdraw-feign-client", url = "127.0.0.1:8081")
public interface WithdrawFeignClient {
    @PostMapping("/withdraw/pullWithdraw")
    @ResponseBody
    CommonResult<List<WithdrawVO>> pullWithdraw(@RequestBody RequestData<PullWithdrawReq> req);
}

客户端调用代码

RequestData requestData = new RequestData();
requestData.setChain(Chain.FIL);
requestData.setDataString("123");
requestData.setData(pullWithdrawReq);
CommonResult<List<com.dhlfy.financerpcclient.WithdrawVO>> result = withdrawFeignClient.pullWithdraw(requestData);

服务端接口代码

@PostMapping("/pullWithdraw")
public CommonResult<List<WithdrawVO>> pullWithdraw(@RequestBody RequestData<PullWithdrawReq> req) {
    String k = formatParma(req);
    PullWithdrawReq withdrawReq = JSONObject.parseObject(k, PullWithdrawReq.class);
    checkSign(withdrawReq);
    return CommonResult.success(withdrawService.pullWithdraw(req.getChain().name(), withdrawReq));
}

内容的提问来源于stack exchange,提问作者Yu Yang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 21:00:09