Error pages in Java Spring

My code used to work back when I didnt use Spring. Now that I’m using it doesn’t work. I’m still getting the usual not found page


<!--Error pages-->
    <!-- Missing resource -->
    <!-- Uncaught exception -->


  //Error pages
public ModelAndView error404() {
    return new ModelAndView("error404");

public ModelAndView error500() {
    return new ModelAndView("error500");