2011-12-25 4 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

사용중인 라이브러리의 버전을 추가하십시오. 당신은 classpath에 바로 jackson 라이브러리를 추가하면된다. 봄철에 사용 된 버전을 확인하려면 봄철 pom을 확인하십시오. –

답변

0

classpath에 jackson 라이브러리를 추가하면 각 @ResponseBody 주석이 달린 컨트롤러 metod에 대해 json이 클라이언트에 반환됩니다.

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

가의 schemaLocation 태그에 ApplicationContext를-web.xml 파일의 상단에있는 스키마에 나열되어 있습니다

0

또한 여부를 확인해야합니다.

관련 문제