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

6tr1vspr  于 2023-11-17  发布在  Spring
关注(0)|答案(1)|浏览(181)

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

  1. @RequestMapping(method = RequestMethod.GET)
  2. public String getCapabilities(@RequestParam(value = "selectedRRCode", required = false) String selectedRRCode,
  3. @RequestHeader(value = "Authorization") String authorization,
  4. @RequestHeader(value = "td-api-consumer-key") String apiConsumerKey) {
  5. String capability;
  6. try {
  7. if () {
  8. //do something
  9. } else {
  10. //do something
  11. }
  12. } catch (Exception e) {
  13. //do something
  14. }
  15. return capability;
  16. }

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

gmxoilav

gmxoilav1#

当您在Spring Boot 中使用以下

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

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

相关问题