spring - Cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] -


it use spring mvc json.i want data in json format.below code. made jsoncontroller.java , shop.java. when run
http://localhost:8080/jsonapi/rest/kfc/brands got error.can 1 tell me need modify in code.

jsoncontroller.java

package com.java; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.pathvariable; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.responsebody;  @controller @requestmapping("/kfc") public class jsoncontroller {     @requestmapping(value="{name}", method = requestmethod.get)     public @responsebody shop getshopinjson(@pathvariable string name) {          shop shop = new shop();         shop.setname(name);         shop.setstaffname(new string[]{"mkyong1", "mkyong2"});          return shop;      }  } 

shop.java

public class shop {     string name;     string staffname[];     public string getname() {         return name;     }     public void setname(string name) {         this.name = name;     }     public string[] getstaffname() {         return staffname;     }     public void setstaffname(string[] staffname) {         this.staffname = staffname;     }  } 

web.xml

<?xml version="1.0" encoding="utf-8"?>     <web-app id="webapp_id" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">     <display-name>spring web mvc application</display-name>      <servlet>       <servlet-name>spring</servlet-name>        <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>        <load-on-startup>1</load-on-startup>        </servlet>        <servlet-mapping>       <servlet-name>spring</servlet-name>        <url-pattern>/rest/*</url-pattern>        </servlet-mapping>        </web-app> 

spring-servlet.xml

<?xml version="1.0" encoding="utf-8"?>         <beans xmlns="http://www.springframework.org/schema/beans"             xmlns:context="http://www.springframework.org/schema/context"             xmlns:mvc="http://www.springframework.org/schema/mvc"              xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"             xsi:schemalocation="                 http://www.springframework.org/schema/beans                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                 http://www.springframework.org/schema/context                  http://www.springframework.org/schema/context/spring-context-3.0.xsd                 http://www.springframework.org/schema/mvc                 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">              <context:component-scan base-package="com.java" />              <mvc:annotation-driven />             <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">           <property name="prefix" value="/web-inf/" />            <property name="suffix" value=".jsp" />          </bean> </beans> 

i got following error when trying run it:

severe: context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter#0': cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.mappingjacksonhttpmessageconverter] while setting bean property 'messageconverters' key [5]; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name '(inner bean)#7': instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [org.springframework.http.converter.json.mappingjacksonhttpmessageconverter]: constructor threw exception; nested exception java.lang.nosuchmethoderror: org.codehaus.jackson.type.javatype.<init>(ljava/lang/class;)v @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolveinnerbean(beandefinitionvalueresolver.java:281)  @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvevalueifnecessary(beandefinitionvalueresolver.java:125)  @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvemanagedlist(beandefinitionvalueresolver.java:355)  @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvevalueifnecessary(beandefinitionvalueresolver.java:153)    @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1308)    @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1067)    @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:511)    @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:450)    @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:290)   @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222)    @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:287)    @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:189)   @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:562)   @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:871)    @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:423)    @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:443)    @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:459)    @ org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:340)    @ org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:307)    @ org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:127)    @ javax.servlet.genericservlet.init(genericservlet.java:160)    @ org.apache.catalina.core.standardwrapper.initservlet(standardwrapper.java:1189)    @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1103)    @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:1010)   @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4935)    @ org.apache.catalina.core.standardcontext$3.call(standardcontext.java:5262)    @ org.apache.catalina.core.standardcontext$3.call(standardcontext.java:5257)     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:334)     @ java.util.concurrent.futuretask.run(futuretask.java:166)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110)    @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603)   @ java.lang.thread.run(thread.java:722)     caused by: org.springframework.beans.factory.beancreationexception: error creating bean name '(inner bean)#7': instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [org.springframework.http.converter.json.mappingjacksonhttpmessageconverter]: constructor threw exception; nested exception java.lang.nosuchmethoderror: org.codehaus.jackson.type.javatype.<init>(ljava/lang/class;)v         @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:946)         @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:892)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:479)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:450)     @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolveinnerbean(beandefinitionvalueresolver.java:270)         ... 31 more 

thanks stackoverflow , jens used spring 3.2.2 , jackson 1.9.10 issue resolved


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -