简体   繁体   中英

java.lang.IllegalStateException: Could not find @PathVariable

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:

In your method handler try to use {question} pathVariable as int, assuming you have int questionid field in your Question JavaBean & try to construct Question JavaBean inside method handler..

@RequestMapping(value = "/site/apps/{question}.json", method = RequestMethod.GET)
public @ResponseBody ServiceResponse moreUsers(
        @PathVariable("question") Integer question,
        @RequestParam(value = "sort", required = false) final String sort,
        final HttpServletRequest request, final Model model){

Question Q=questionservice.getQuestion(question);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM