【问题标题】:Ambiguous handler error for Spring Boot Error controllerSpring Boot Error 控制器的不明确处理程序错误
【发布时间】:2021-01-12 05:41:59
【问题描述】:

我已经遇到这个问题有一段时间了,但我似乎无法找到为什么会出现这个模棱两可的错误。

这是我得到的错误:

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)}

这是我的 http 配置:

.and().exceptionHandling().accessDeniedPage("/AccessDenied").

这是我的 /AccessDenied 控制器:

@RequestMapping(value = "/AccessDenied")
public ModelAndView accessDenied() throws Exception {
    ModelAndView model = new ModelAndView("accessDenied");
    
    return model;
}

真的希望你能帮助我。谢谢。

【问题讨论】:

    标签: spring spring-boot ambiguous


    【解决方案1】:

    Spring 找不到处理错误的终点。我认为您应该为@RequestMapping 指定Http 方法。另外,this answer 可能有用。

    更新 另外,我发现 here 你可以在 accessDeniedPage() 方法中指定 html 页面。例如,您可以创建error.htmlerror.jsp 并将其添加到您的代码.and().exceptionHandling().accessDeniedPage("/error.jsp") 中。在这种情况下,您不再需要在控制器中处理此请求。

    【讨论】:

    • 谢谢! .accessDeniedPage("/error.jsp") 工作。 :)
    猜你喜欢
    • 2020-01-05
    • 1970-01-01
    • 2015-06-24
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2016-04-16
    • 1970-01-01
    相关资源
    最近更新 更多