spring - @ControllerAdvice Annotation not working -
i know question has been asked, solutions proposed not working me. @ startup bean resterrorhandler gets created , it's constructor called. when throw runtime exception in controller not invoking error handler. instead invokes default handler:
type=debug,category=org.springframework.web.servlet.mvc.support.defaulthandlerexceptionresolver,thread="http-bio-8080"-exec-3,mdc=,text=resolving exception handler [public org.springframework.http.responseentity<com.egencia.auth.message.createpasswordpolicyresponse> com.egencia.service.controller.passwordpolicyendpoint.createpasswordpolicy(com.egencia.auth.message.createpasswordpolicyrequest,java.lang.string)]: java.lang.runtimeexception the controlleradvice .
@controlleradvice public class resterrorhandler extends responseentityexceptionhandler { private static final logger logger = loggerfactory .getlogger(resterrorhandler.class); private map<class<? extends exception>, httpstatus> statuses; public resterrorhandler() { map<class<? extends exception>, httpstatus> map = new hashmap<class<? extends exception>, httpstatus>(); map.put(illegalargumentexception.class, httpstatus.bad_request); map.put(unsupportedoperationexception.class, httpstatus.bad_request); map.put(badsqlgrammarexception.class, httpstatus.bad_request); map.put(dataintegrityviolationexception.class, httpstatus.bad_request); map.put(httpmessageconversionexception.class, httpstatus.bad_request); map.put(httpmediatypeexception.class, httpstatus.bad_request); statuses = map; } /** * map exception type http status. * * @param statuses * statuses set */ public void setstatuses(map<class<? extends exception>, httpstatus> statuses) { this.statuses = statuses; } @exceptionhandler({runtimeexception.class}) public responseentity<object> processerror(exception ex, webrequest request) { logger.debug("inside rest error handler"); } }
i have tried @enablewebmvc annotation well.
try annotate resterrorhandler @controller annotation
spring spring-mvc
No comments:
Post a Comment