This is what my REST controller looks like
@RequestMapping(method = GET, path = "/type/{eventtype}/events")
@ResponseBody
public ResponseEntity<?> getEventsSpecificType(@PathVariable String eventType) throws InvalidRequestException {
return ResponseRestBuilder.createSuccessResponse(
portEventRepository.
findByEventTypeOrderByTimestampAsc
(eventType));
}
Calling it from Postman with the following URI
http://localhost:8181/type/default/events
gets me this error
{
"timestamp": 1518605163296,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.web.bind.MissingPathVariableException",
"message": "Missing URI template variable 'eventType' for method parameter of type String",
"path": "/type/default/events"
}
What am I missing? Isn't the String variable properly mapped?
You must give the name of the path variable, the name of the method parameter doesn't matter. And the name of the path variable must match exactly the name used in your Path (eventtype).
getEventsSpecificType(@PathVariable("eventtype") String eventType)
If you don't specify the @PathVariable, the name must match exactly the name used in the path. So change the eventType method parameter to eventtype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With