I am a very beginner in spring
. In my application, I created a global exception handler class using @ControllerAdvice
. It is catching all 5xx errors. But when it is getting some 403 error, it is showing the default page.
My calls file is
package com.example.learn.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
@Slf4j
@ControllerAdvice
public class GlobalExceptionController {
@ExceptionHandler(Exception.class)
public ModelAndView exceptionHandler(Exception exception) {
ModelAndView errorPage = new ModelAndView();
errorPage.setViewName("error");
errorPage.addObject("errormsg", exception.getMessage());
return errorPage;
}
}
And when it is getting some 403 error the below page is coming
How can I show a custom error page instead of this in the global exception handler?
Spring Version: 3.0.5
Java version: 17
Build using maven
Thanks in advance