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

Web.xml

<!--Error pages-->
<error-page>
    <!-- Missing resource -->
    <error-code>404</error-code>
    <location>/error404</location>
</error-page>
<error-page>
    <!-- Uncaught exception -->
    <error-code>500</error-code>
    <location>/error500</location>
</error-page>

Controller

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

@RequestMapping("/error500")
public ModelAndView error500() {
    return new ModelAndView("error500");
}