Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing URI template variable for method parameter of type String

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?

like image 982
Pierangelo Calanna Avatar asked May 19 '26 04:05

Pierangelo Calanna


1 Answers

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.

like image 134
Mathias G. Avatar answered May 21 '26 20:05

Mathias G.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!