java - Spring error handling does not work -


there many topics, but... have proper return parameters , arguments, read, necessary. wrong?

<servlet>     <servlet-name>springmvc</servlet-name>     <servlet-class>com.vse.uslugi.utilities.web.basedispatcherservlet</servlet-class>     <load-on-startup>1</load-on-startup> </servlet>  import org.springframework.web.bind.annotation.exceptionhandler; import org.springframework.web.bind.annotation.responsebody; import org.springframework.web.servlet.dispatcherservlet;  public class basedispatcherservlet extends dispatcherservlet { @responsebody @exceptionhandler(exception.class) public string handlethrowable() {     return errorservice.html("internal server error"); }  @responsebody @exceptionhandler(resourcenotfoundexception.class) public string handleresourcenotfoundexception() {     return errorservice.html("page not found"); } } //-------------------- import org.springframework.http.httpstatus; import org.springframework.web.bind.annotation.responsestatus;  @responsestatus(httpstatus.not_found) public class resourcenotfoundexception extends runtimeexception { } 

the dispatcher servlet being instantiated application server it's not spring managed.

some options have:

  1. add @exceptionhandler method controller.
  2. add bean spring context has @exceptionhandler methods on , annotate class @controlleradvice, apply controllers default.

Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -