I'm currently working on an existing project (java version: 1.7.0, using Spring MVC framework version: 3.1.4) where we only have located this PathVariable
issue in only one URI of an specific controller class, and I would really appreciate if any of you have already faced this error and how did you fix/solve it? Thanks!
Code (extracted part of the java controller class):
@RequestMapping(value = "/site/apps/{question}.json", method = RequestMethod.GET)
public @ResponseBody ServiceResponse moreUsers(
@PathVariable("question") final Question question,
@RequestParam(value = "sort", required = false) final String sort,
final HttpServletRequest request, final Model model)
Error output of our tomcat log (catalina.out file):
ERROR Error executing request: /site/apps/52440.json
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public com.project.infrastructure.service.ServiceResponse com.project.plugins.controllers.SiteAppController.moreUsers(com.project.models.node.Question,java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.Model)]; nested exception is java.lang.IllegalStateException: **Could not find @PathVariable [question] in @RequestMapping**
What we've already researched:
- followed spring convention for PathVariable annotation according to the specification doc (mvc-ann-requestmapping-uri-templates),
- No other similar path has been found on the java project, that will maybe have a conflict matching within (/site/apps/{question-id})
- we've also logged the mapping and looks good, according to the mappedPattern value (located here: https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java#L755-L764)
- the interesting thing comes when calling resolvePathVariable spring method, since the "URI Template Variable Map" value is null (https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java#L853-L854 and don't know why!