I have a scenario where I’m making a simple get request through a link and my @RequestMapping configuration is not behaving as I’d expect.
Within an anchor tag I reference a url with the following pattern ‘/action-plan/export/pdf?token=xxx&taskId=1111&taskId=2222…’
Within my controller class I have this mapping at the class level:
@RequestMapping("/action-plan/export")
And this mapping at the method level
@RequestMapping(value="/pdf", method=RequestMethod.GET)
public String exportToPdf(@RequestParam("taskId") String[] taskIds,
@RequestParam("token") String[] encryptedEmplId, ModelMap model)
But every time I try this I get a 404 page not found error and the following Spring exception:
org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException: No matching handler method found for servlet request: path ‘/pdf’, method ‘GET’, parameters map[‘taskId’ -> array[‘1962326’, ‘1962264’, ‘1962317’, ‘1962328’, ‘1962324’, ‘1962427’, ‘1962325’, ‘1962323’, ‘1963147’, ‘1962327’, ‘1962318’, ‘1962329’, ‘1962330’], ‘token’ -> array[‘xxxx’]]
I’ve noticed that when I remove the “/pdf?” portion of the link and remove ‘value=”/pdf”‘ from the method @RequestMapping it works fine. For the life of me I don’t understand why adding /pdf to the url and RequestMapping is not working.
I think danny.lesnik’s answer was pretty close but I’m writing my own answer so I can be more verbose.
I was working on a different project and figured out why the above doesn’t work. In reference to my original question here is the relevant web.xml servlet mapping:
I noticed that whatever portion of the path I included in the of web.xml was not being included in the evaluation of RequestMapping values. I would have thought this bean configuration would have prevented that scenario (note the “alwaysUseFullPath” property):
Maybe someone can shed some light on this detail for me.
In any case, thanks danny.lesnik