2011-12-25 12 views
0

Spring 3.0 MVCを使用してRESTを開発したいのですが...非常に簡単なコードをテストしますが、org.springframework.beans.factory.BeanCreationExceptionがスローされましたここに私のコードは次のとおりです。Spring MVC REST:org.springframework.beans.factory.BeanCreationExceptionがスローされました

@Controller 
public class RestTest { 


    @RequestMapping(method=RequestMethod.GET, value="/1", 
      headers="Accept=application/json") 
    public @ResponseBody Employee getEmp(@PathVariable String id) { 
    Employee e = new Employee("helloWorld","stip of world"); 
    return e; 
    } 


} 

豆-XML:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    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"> 
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
    <property name="messageConverters"> 
     <list> 
      <ref bean="jsonConverter" /> 

     </list> 
    </property> 
</bean> 

<bean id="jsonConverter" 
      class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> 
    <property name="supportedMediaTypes" value="application/json" /> 
</bean> 
<context:component-scan base-package="org.stip.rest"></context:component-scan> 
</beans> 

例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Cannot resolve reference to bean 'jsonConverter' while setting bean property 'messageConverters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonConverter' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.isFullyTyped()Z

jackson-core.jarとjackson-mapperがビルドパスに追加されました... 私は修復するために最善を尽くしていますが...助けてください...ありがとう

+1

どのバージョンのjacksonを使用していますか?Spring 3との互換性を確認しましたか? –

+0

@AravindA 1.90..iは互換性をチェックしませんでした...どのバージョンが好きですか? – user996505

+0

使用しているライブラリのバージョンを追加してください。クラスパスに適切なjacksonライブラリを追加するだけで、うまくいくはずです。春に使用されたバージョンを取得するには、春のポンを確認してください。 –

答えて

0

jacksonライブラリをクラスパスに追加すると、@ResponseBody注釈付きコントローラのmetodごとにjsonがクライアントに返されます。

0

またかどうかをチェックしてください:

"http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" 

はschemaLocationのタグであなたのApplicationContext-web.xmlのの先頭にスキーマに記載されています。

関連する問題