java - Spring JsonProcessingExceptin NoClassDefFoundError for rest template -
i using jackson parser, , works rest template when requesting when try post gives me following error:
web.util.nestedservletexception: handler processing failed; nested exception java.lang.noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
i don't know went wrong. i'm trying send post request , body should object:
@requestmapping(value = "dogcreated", method = requestmethod.post) @responsestatus(httpstatus.created) public string createdog(@modelattribute dog dog, bindingresult result, model model){ resttemplate rest = new resttemplate(); // list< httpmessageconverter<?> > messageconverters = new arraylist< httpmessageconverter<?> >(); // // empty list created // // messageconverters.add( new mappingjackson2httpmessageconverter() ); // messageconverters.add( new stringhttpmessageconverter() ); rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());/*this error occurs*/ rest.getmessageconverters().add(new stringhttpmessageconverter()); objectmapper mapper = new objectmapper(); typefactory typefactory = mapper.gettypefactory(); string response = rest.postforobject("https://rest-service.herokuapp.com/createdog", dog, string.class); system.out.println(response);
i have included both jackson dependencies in pom.xml:
<dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-core-asl</artifactid> <version>1.9.13</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.9.13</version> </dependency>
can tell me going wrong? more says error occurs on line:
rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());
any appreciated.
this full stack trace
org.springframework.web.util.nestedservletexception: handler processing failed; nested exception java.lang.noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception org.springframework.web.servlet.dispatcherservlet.triggeraftercompletionwitherror(dispatcherservlet.java:1303) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:977) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:967) org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:869) javax.servlet.http.httpservlet.service(httpservlet.java:648) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:843) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause java.lang.noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception com.dogs.controller.dogcontroller.createdog(dogcontroller.java:42) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) java.lang.reflect.method.invoke(method.java:483) org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221) org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:776) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:705) org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:967) org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:869) javax.servlet.http.httpservlet.service(httpservlet.java:648) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:843) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause java.lang.classnotfoundexception: com.fasterxml.jackson.core.jsonprocessingexception org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1305) org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1157) com.dogs.controller.dogcontroller.createdog(dogcontroller.java:42) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) java.lang.reflect.method.invoke(method.java:483) org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221) org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:776) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:705) org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:967) org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:869) javax.servlet.http.httpservlet.service(httpservlet.java:648) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:843) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)
the problem have because using old dependencies latest spring doesn't support:
<dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-core-asl</artifactid> <version>1.9.13</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.9.13</version> </dependency>
since above libraries changed little bit need remove dependencies , put new one:
<dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.5.4</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> <version>2.5.4</version> </dependency>
change , see results. if works make answered.
Comments
Post a Comment