As you know, in XML, the way to configure this is:
<error-page>
<error-code>404</error-code>
<location>/my-custom-page-not-found.html</location>
</error-page>
But I haven't found a way to do it in Java config. The first way I tried was:
@RequestMapping(value = "/**")
public String Error(){
return "error";
}
And it appeared to work, but it has conflicts retrieving the resources.
Is there a way to do it?
For Java config there is a method
setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound)
inDispatcherServlet
. By settting it totrue
I guess you are doing same thingthen you can can this
NoHandlerFoundException.class
in controller advice as stated in above answerit will be like something