What I want to do is that when user enters url which leads nowhere, I mean there is no resources by this url than special mapping should work.
For example, I have next controller:
@Controller
public class LoginController {
@RequestMapping(value = {"/", "/login"}, method = RequestMethod.GET)
public ModelAndView welcome() {
return new ModelAndView("mainPage");
}
}
This mapping works when when user enters {contextPath}/ or {contextPath}/login Now i want to map all other urls, I do like this:
@Controller
public class LoginController {
@RequestMapping(value = {"/", "/login"}, method = RequestMethod.GET)
public ModelAndView welcome() {
return new ModelAndView("mainPage");
}
@RequestMapping(value = {"/**"}, method = RequestMethod.GET)
public ModelAndView notFound() {
return new ModelAndView("customized404Page");
}
}
Now when user enters invalid path for example {contextPath}/sdfsdf customized404Page is shown to him
But last mapping is more general and and it works always and that is why first mapping doesn`t work.
Question: How to map all invalid urls? Or maybe there is some simplier way to to this in Spring?