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:
- add
@exceptionhandler
method controller. - add bean spring context has
@exceptionhandler
methods on , annotate class@controlleradvice
, apply controllers default.
Comments
Post a Comment