java - spring 4 mvc app - application level exception handler -


i moving spring web app spring 3.2 4.1.

in 3.2, following exception handler works catching exceptions entire applicaton.

@controlleradvice public class restexceptionprocessor {     @org.springframework.web.bind.annotation.exceptionhandler(appexception.class)     @responsebody     public errorinfo handleappexception(appexception ex, httpservletresponse response) {         errorinfo ret = new errorinfo(ex.getmessage(), new date(), ex.getextras());         logger.error(ex.getmessage());         response.setstatus(ex.getcode().getstatuscode());          return ret;     } } 

however when move 4.1, following exception stack trace:

error failed invoke @exceptionhandler method: public com.momoe.handler.restexceptionprocessor$errorinfo com.momoe.handler.restexceptionprocessor.handleappexception(com.momoe.commons.appexception,javax.servlet.http.httpservletresponse) org.springframework.web.httpmediatypenotacceptableexception: not find acceptable representation     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:134) ~[spring-webmvc-4.1.6.release.jar:4.1.6.release]     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:101) ~[spring-webmvc-4.1.6.release.jar:4.1.6.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.handlereturnvalue(requestresponsebodymethodprocessor.java:167) ~[spring-webmvc-4.1.6.release.jar:4.1.6.release]     @ org.springframework.web.method.support.handlermethodreturnvaluehandlercomposite.handlereturnvalue(handlermethodreturnvaluehandlercomposite.java:71) ~[spring-web-4.1.6.release.jar:4.1.6.release]     @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:126) ~[spring-webmvc-4.1.6.release.jar:4.1.6.release]     @ org.springframework.web.servlet.mvc.method.annotation.exceptionhandlerexceptionresolver.doresolvehandlermethodexception(exceptionhandlerexceptionresolver.java:362) ~[spring-webmvc-4.1.6.release.jar:4.1.6.release]..... 

how can fix this?

when upgrading spring 3.x 4.1 need change jackson 1.9.x jackson 2.x. in jackson 2.x package structure got migrated org.codehaus com.fasterxml.

if don't have com.fasterxml jackson on classpath result same if you're missing jackson altogether, outputting could not find acceptable representation message in logs. if you're using maven should enough include jackson-databind, transitively include jackson-annotation , jackson-core

<dependency>     <groupid>com.fasterxml.jackson.core</groupid>     <artifactid>jackson-databind</artifactid>     <version>2.5.1</version> </dependency> 

a bit more details available here spring 4 restcontroller json: characteristics not acceptable according request "accept" headers


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -