0
votes

I want to use Spring 3.0 MVC to develop REST...I test a very simple code ,but org.springframework.beans.factory.BeanCreationException was thrown here is my code:

@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;
    }


}

beans-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>

the exception:

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 and jackson-mapper have been added to the build path... i try my best to fix..but..Can you help me ...Thanks

2
which version of jackson are you using?Did you check its compatibility with Spring 3?Aravind A
@AravindA 1.90..i didn't check compatibility...which version is prefer?user996505
Please add the version of the libraries you are using. You should just add the right jackson libraries to the classpath and it should work. Check the spring pom to get the version used by spring.Kevin Bayes

2 Answers

0
votes

Yo dont need register converter if you add jackson library to your classpath spring will return json to client for each @ResponseBody annotated controller metod.

0
votes

Also make sure to check if:

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

are listed in the schemas at the top of your applicationContext-web.xml in the schemaLocation tag.