【问题标题】:Spring boot : REST API behaviour inconsistent post version upgradeSpring boot:REST API 行为不一致后版本升级
【发布时间】:2021-11-15 21:17:28
【问题描述】:

从 1.5.10.RELEASE 升级到 Spring Boot 2.3.0.RELEASE 后出现问题。我们的控制器 API 看起来像 -

@RequestMapping(value = "/card", method = RequestMethod.GET)
public CardRespDTO getCards(@RequestParam String profileId, @RequestParam(required = false) String banner, @RequestParam(required = false) String paymentGatewayVersion);

消费者能够通过不传递 profileId 参数而只需提供一些 USER_ID 标头来调用此 API。但是发布版本升级后,这些调用失败并出现以下错误 -

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'profileId' is not present

有人可以帮忙找出这里的问题吗?我们不能要求消费者做出改变。

【问题讨论】:

  • 我猜你还需要为 profileId 设置 required=false,@RequestParam(required = false) String profileId。
  • 谢谢@OnkarMusale

标签: spring-boot rest spring-mvc


【解决方案1】:

profileId 标记为不需要就可以了:

@RequestMapping(value = "/card", method = RequestMethod.GET)
public CardRespDTO getCards(@RequestParam(required = false) String profileId, 
    @RequestParam(required = false) String banner, 
    @RequestParam(required = false) String paymentGatewayVersion)

【讨论】:

    猜你喜欢
    • 2020-04-23
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2018-06-28
    • 2022-11-25
    • 1970-01-01
    相关资源
    最近更新 更多