Java Spring persist stack trace when 500 error happens -
i hosting spring boot application on amazon ec2. in morning when go webpage see
"could not open jpa entitymanager transaction; nested exception javax.persistence.persistenceexception: org.hibernate.transactionexception: jdbc begin transaction failed:"
from browser. have no way stack trace. possible in spring: when 500 error happens, spring catch exception , store in database or local file can later. think helpful debug hard-to-reproduce 500 errors.
yes possible need configure controllers use spring exception handling https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
then can configure level of exceptions want catch(in case general exception ok, or if know specific exception better)
// total control - setup model , return view name yourself. or consider // subclassing exceptionhandlerexceptionresolver (see below). @exceptionhandler(exception.class) public modelandview handleerror(httpservletrequest req, exception exception) { logger.error("request: " + req.getrequesturl() + " raised " + exception); //here can persist exception or write in log modelandview mav = new modelandview(); mav.addobject("exception", exception); mav.addobject("url", req.getrequesturl()); mav.setviewname("error"); return mav; } }
Comments
Post a Comment