Spring Boot 请求标头丢失,尽管已成功传递

6tr1vspr  于 7个月前  发布在  Spring
关注(0)|答案(1)|浏览(87)

我已经在Sping Boot 中构建了一个Web应用程序。这是来自Controller的代码:

@RequestMapping(method = RequestMethod.GET)
public String getCapabilities(@RequestParam(value = "selectedRRCode", required = false) String selectedRRCode,
        @RequestHeader(value = "Authorization") String authorization,
        @RequestHeader(value = "td-api-consumer-key") String apiConsumerKey) {
String capability;
try {
    if () {
        //do something
    } else {
        //do something
    }
} catch (Exception e) {
    //do something
}
return capability;
}

字符串
我获得的错误是:ExceptionHandlerExceptionResolver:146 resolveException - Resolved [org.springframework.web.bind.MissingRequestHeaderException:方法参数类型的请求头'td-api-consumer-key'不存在]
可能是什么问题?我正在将此应用程序从Spring 5迁移到springboot 2.7。它在Spring 5中运行良好。请让我知道我在这里错过了什么。谢谢

gmxoilav

gmxoilav1#

当您在Spring Boot 中使用以下

@RequestHeader(value = "td-api-consumer-key")

字符串
默认值是“requried”。你没有提供这个头。所以,为了缓解这个问题,你可以先尝试require=“false”来证明它。

相关问题