Issue
I am using Spring MVC 3 and am having an issue with a URL mapping. I have a method
@Controller
public class DocumentController {
@RequestMapping( value="/docs/pupil/classes/{courseCategoryType}", method=RequestMethod.GET )
public ModelAndView listClassesForPupil( @PathVariable("courseCategoryType") final String courseCategoryType ){
System.err.print( "\n\n\n\t\t--- XXXXX ---\n\n\n" );
}
}
I am trying to use the Spring URI template syntax, and I know that is getting mapped because in console I see:
11:22:12,108 INFO DefaultAnnotationHandlerMapping:411 - Mapped URL path [/docs/pupil/classes/{courseCategoryType}] onto handler 'documentController'
11:22:12,108 INFO DefaultAnnotationHandlerMapping:411 - Mapped URL path [/docs/pupil/classes/{courseCategoryType}.*] onto handler 'documentController'
11:22:12,108 INFO DefaultAnnotationHandlerMapping:411 - Mapped URL path [/docs/pupil/classes/{courseCategoryType}/] onto handler 'documentController'
However, when I enter the URLhttps://localhost/docs/pupil/classes/ACADEMIC
in browser I get a 404 error and I do not see anything printed out in the console. I replaced the print out code that just throws an exception, and it didn't seem to get thrown either. A coworker suggested there should be a way of viewing how the URL resolution is being done but a Google search didn't seem to turn up anything.
Any suggestions as how to debug this?
Solution
For problems like this I feel like the best "entrypoint" to start debugging is the method getHandler(HttpServletRequest request)
of the DispatcherServlet
.
Inside this method every configured HandlerMapping
is inspected if it responsible for handling your specific request. If your request makes it this far, you can be quite sure that it is a configuration problem inside the spring context.
Watch out for handlers of the type RequestMappingHandlerMapping
(or DefaultAnnotationHandlerMapping
, if you are using an older version of Spring), these are normally the HandlerMapping
used by annotation based Controller configuration.
In the other case, make sure there is nothing "in front" of the DispatcherServlet
filtering your requests (like in your case)
Answered By - Patrick