每个请求都会调用Spring Error Controller

时间:2017-09-19 16:58:08

标签: java spring

我的应用程序中存在一种奇怪的行为。 我有一个错误控制器来映射某种错误并记录它。

我有这个例外

@ResponseStatus(value=HttpStatus.NOT_FOUND)
public class ResourceNotAccessibleException extends RuntimeException{

public ResourceNotAccessibleException(String message) {
        super(message); 
}

比,我有这个控制器

@Controller
public class ErrorController {

@GetMapping("/errors")
    @ExceptionHandler({ResourceNotAccessibleException.class})
    public ModelAndView getErrorPage(HttpServletRequest request, RuntimeException ex) {

int httpErrorCode = getErrorCode(request);
String errorMsg = messageSource.getMessage("errorMessage.404", null, locale);
            logger.error("Status Error " + httpErrorCode +  getErrorMessage(request));

ModelAndView mav = new ModelAndView();
        mav.addObject("errorMessage", errorMsg);
        mav.addObject("errorCode", httpErrorCode);
        mav.setViewName("error");

        return mav;

}

我还有一个bean pin我的配置来映射这个错误页面

@Component
public class CustomizationBean implements EmbeddedServletContainerCustomizer {



  @Override
  public void customize(ConfigurableEmbeddedServletContainer container) {

    container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/errors"));
  }

}

现在,奇怪的行为是我在应用程序的每个页面中看到404错误的日志,而不仅仅是在抛出异常时...

我不知道我还能提供什么...

0 个答案:

没有答案