When using
Spring annotation based controllers,
@RequestMapping
must be applied to a method as well as the class or it will not work. For example:
@Controller
@RequestMapping("/blah.html")
public MyController {
@ModelAttribute("session")
public InventorySession getSession() {
return session;
}
}
Will result in
No mapping found for HTTP request with URI [/[contextpath]/blah.html]
errors. Request methods (or sub-pages) must be mapped to controller methods, i.e.:
. . .
@RequestMapping(method={RequestMethod.GET})
public String getForm() {
return "formView.jsp";
}
. . .
This mistake is particularly easy to make when migrating older code to the newer annotation based model, where mappings on legacy code may make it (erroneously) appear such linking is done in the xml file already.