Swagger MethodArgumentTypeMismatchException:无法将参数转换为类型

问题描述

昂首阔步有奇怪的行为。我正在使用3.0.0版。

我的记录器中的错误MethodArgumentTypeMismatchException: The parameter 'configId' of value '{configId}' Could not be converted to type 'Long'

昂首阔步的错误显示

{
  "status": "BAD_REQUEST","timestamp": "07-10-2020 04:23:55","message": "The parameter 'configId' of value '{configId}' Could not be converted to type 'Long'","debugMessage": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: \"{configId}\"","subErrors": null
}

怎么可能是\"{configId}\"?我在做什么错了?

我的方法如下:

  @ApiOperation(
      value = "Deletes a configuration of a custom MLP in the database",notes = "This can only be done by the owner of the config.",response = ResponseEntity.class,authorizations = @Authorization(value = "Bearer"))
  @ApiResponses(
      value = {
        @ApiResponse(code = 200,message = "Successfully deleted custom MLP configuration"),@ApiResponse(code = 401,message = "You are not authorized to delete the resource"),@ApiResponse(
            code = 403,message = "Accessing the resource you were trying to reach is forbidden"),@ApiResponse(code = 404,message = "The resource you were trying to reach is not found")
      })
  @PreAuthorize("@mlpConfigServiceImpl.ownedByUser(#mlpConfigId,authentication.name)")
  @DeleteMapping(value = "/delete/{configId}")
  public ResponseEntity<Object> deleteMlpConfig(
      @ApiParam(
              name = "MlpConfig Id",value = "Id of a custom MLP configuration",type = "long",format = "long",example = "1")
          @PathVariable("configId")
          @NotNull
          Long mlpConfigId,Authentication authentication) {
    mlpConfigService.deleteById(mlpConfigId);
    return ResponseEntity.ok(new MessageResponse("Configuration removed successfully!"));
  }

唯一有趣的路径是:

 @ApiParam(
           name = "MlpConfig Id",example = "1")
      @PathVariable("configId")
      @NotNull
      Long mlpConfigId,

我的依赖关系:

compile group: 'io.springfox',name: 'springfox-swagger2',version: '3.0.0'
compile group: 'io.springfox',name: 'springfox-swagger-ui',name: 'springfox-boot-starter',name: 'springfox-data-rest',name: 'springfox-bean-validators',version: '3.0.0'

我唯一想做的就是给1作为示例ID并能够执行它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)