Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ' "Missing URI template variable 'uuid' for method parameter of type UUID"'?

I have updated the pathvariable from String to UUID in the controller of a spring-boot implemented web application. I am using swagger for the front end. I am getting "Missing URI template variable 'uuid' for method parameter of type UUID" exception in the response after the change.

I have updated the pathvariable from String to UUID in the controller of a spring-boot implemented web application. I am using swagger for the front end. At the db side I am using mongodb. I am converting this uuid to string to use the exiting find method implemented for mongodb. I am getting this exception in the response. The same thing is working in another project, Couldn't find out why it is not working here.

@Path("/uuid")
@RequestMapping(value = "/uuid", method = { RequestMethod.GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Retrieves result based on Unique Identifier", notes = "Returns result matching with the Unique Identifier", 
    position = 1, response = Response.class, httpMethod = "GET")
@ApiResponses(value = { @ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Invalid request."),
        @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "Record not found."),
        @ApiResponse(code = HttpServletResponse.SC_FORBIDDEN, message = "Not authorized for this operation."),
        @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "Object state out-of-date."),
        @ApiResponse(code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message = "Server error") })
ResponseEntity<Response> getResultByUuid(@ApiParam(required = true, name = "uuid", value = "uuid") @PathParam("uuid") @PathVariable("uuid") UUID uuid,
        @ApiParam(access = "hidden") HttpServletRequest request)
        throws IOException;
  1. It should be fetching me the result instead. Now it throws the exception. It doesn't even reach the controller, suspecting some spring configuration dependency stuff. Not sure what is that?
like image 208
Kusum Avatar asked Dec 07 '25 03:12

Kusum


1 Answers

Path variable must be mentioned in the request mapping in curly brackets. In your code the following line

@RequestMapping(value = "/uuid", method = { RequestMethod.GET })

can be changed to

@RequestMapping(value = "/{uuid}", method = { RequestMethod.GET })

to fix that error.

like image 73
Ivan Gammel Avatar answered Dec 08 '25 18:12

Ivan Gammel