Reputation: 572
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?
Upvotes: 3
Views: 28718
Reputation: 189
I have also got same Issue and Resolved by **Changing Name of Path variable Like
@RequestMapping(method = GET, path = "/type/{eventType}/events")
@ResponseBody
public ResponseEntity<?> getEventsSpecificType(@PathVariable String eventType) throws InvalidRequestException {
Upvotes: 0
Reputation: 5095
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.
Upvotes: 8