I've been encountering this for a while now but I can't seem to find the reason why I'm getting this ambiguous error.
This is the error that I'm getting:
Sep 25 21:23:27 ip-172-31-29-87 web: java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://172.31.29.87/error': {public org.springframework.web.servlet.ModelAndView com.sample.controller.WebsiteController.error404() throws java.lang.Exception, public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)}
This is my http configuration:
.and().exceptionHandling().accessDeniedPage("/AccessDenied").
This is my /AccessDenied controller:
@RequestMapping(value = "/AccessDenied")
public ModelAndView accessDenied() throws Exception {
ModelAndView model = new ModelAndView("accessDenied");
return model;
}
Really hope you could help me. Thank you.
Spring couldn't find your end-point for handling error. I think you should specify Http method for @RequestMapping
. Also, this answer might be useful for use.
Upd
Also, I found here what you can just specify html page in accessDeniedPage()
method. For example, you can create error.html
or error.jsp
and add this into your code .and().exceptionHandling().accessDeniedPage("/error.jsp")
. In this case you don't need anymore handle this request in your controller.