Announcement Announcement Module
Collapse
No announcement yet.
Cannot create bean of type MappingJacksonHttpMessageConverter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot create bean of type MappingJacksonHttpMessageConverter

    Hi all,

    I'm having an interesting problem getting output in JSON format from a web app. Deploying the war on Glassfish 2.1.1 on OS X 10.6 and Ubuntu 9.10 I get the following exception:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with 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' with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6': 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.VerifyError: Cannot inherit from final class
    My goal is to get JSON output from my controllers using the MappingJacksonJsonView. I'm using the mvc:annotation-driven element in my -servlet.xml file, though I also tried configuration through a ContentNegotiatingViewResolver with the same result. I am using the jackson-core-asl-1.2.1.jar and jackson-mapper-asl-1.2.1.jar files from http://wiki.fasterxml.com/JacksonDownload. I have also tried Jackson core and mapper 1.3.3 and 1.4.1

    I've been on Google for hours trying to find anything helpful and came up empty handed. Has anyone seen this before? Do I have a ridiculous problem in my configuration? This web app worked before I tried to add JSON output.

    My -servlet.xml config file is:

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:jee="http://www.springframework.org/schema/jee"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           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/jee 
                               http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                               http://www.springframework.org/schema/mvc
                               http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
      <import resource="services.xml"/>
    
      <context:component-scan base-package="some.package"/>  
      <mvc:annotation-driven/>
    
      <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
        <property name="prefix" value="/WEB-INF/jsp/"/> 
        <property name="suffix" value=".jsp"/>
      </bean>
    </beans>
    The full stack trace is attached to this post.

    If anyone has seen this problem before and can point me in the right direction I'd be very happy. Every sample I've seen indicates it's easy to get the MappingJacksonJsonView working but my problem starts even before I get into my own code I think.

    Thank you to anyone that offers some help!

    Anthony

  • #2
    Replying to my own post: This app works just fine on Tomcat 6.0.24 right out of the box. I still have no idea what's wrong with running it on Glassfish 2.1.1.

    Comment


    • #3
      Hi there!

      I don't know if this is of any comfort to you but I'm facing the same problems on jetty (6.X) and tomcat (5.5.X). The fact that you've succesfully deployed on tomcat 6 gives me a bit of hope and I'll try to look into this shortly.

      Regards
      John

      Comment


      • #4
        Hi John,

        Thanks for the reply. I feel better knowing I'm not the only one that has seen this problem. Now that I know it's not just me I may spend a little more time with it to see exactly what's wrong. Let me know how you do with deploying on Tomcat 6.0.24.

        Anthony

        Comment


        • #5
          Hi there!

          I've fixed this issue by replacing jackson-asl-0.9.4.jar with jackson-asl-0.9.5.jar in glassfish-v.2.1.1/lib folder

          Comment


          • #6
            Hey,

            I have the same issue with Spring 3.0.1 and jackson-asl 1.8.3 (the latest version as of today) running on Tomcat 6.0.32. I did try with the earlier versions of the jackson json library but to no avail, the same error at tomcat startup persists. Basicly I'm trying to follow the Spring json guide at
            http://www.ibm.com/developerworks/we...x.html?ca=drs-
            but it does not say which version of the jackson json library to use. Any ideas here?
            Btw what is the difference between the jackson-asl and jackson-lgpl, are they just two implementations of the same thing or?

            Any help would be most appreciated, thanks.

            PS
            The stacktrace from Tomcat is
            Code:
            org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.
            mvc.annotation.AnnotationMethodHandlerAdapter#1' defined in ServletContext resource [/WEB-INF/rest-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 Se
            rvletContext resource [/WEB-INF/rest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework
            .beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJack
            sonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: Cannot inherit from fi
            nal class
                    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueRes
            olver.java:328)
            A REALLY WEIRD THING is that the deploy was actually WORKING before I started to fix my Maven pom.xml with the jackson dependencies, but for some strange reason I cannot get back to that state.
            Any1 has any similar experiences and any suggestions on how to fix it? Does Tomcat have any hidden cache which can be cleared or similar? I did mvn clean to rebuild everything of course.
            When the deploy was working the logic of the json REST web service was somewhat weird, I tested with the REST client plugin for Firefox and even though I added header Accept=application/json it gave the "content not accepted" error. Without that accept header it said that the RequestMethod GET was not accepted, so the header atleast has significance. I debugged and confirmed that my methods got called, and since the "content not accepted" error is somewhat illogcal (since it is accepted on both ends) I thought it might be that the actual json building is the real issue.
            DS
            Last edited by Vassago; Jul 18th, 2011, 04:24 AM.

            Comment


            • #7
              Ok I got back to my original state of the deploy WORKING without any weird cannot instantiate exception. I found this for me very valuable reference
              http://ebr.springsource.com/reposito...rk.web.servlet
              which says that Spring 3.0.1 actually uses the very old org.codehaus.jackson version 1.0 -as mentioned I tried with the latest 1.8.3 and backwards towards 1.1, neither of them worked.
              So I removed all newer versions of org.codehaus.jackson and did a clean build with 1.0, and voila, the deploy is working again.

              Thus the issue now is to find out why the json REST web service is not working as expected.
              The relevant part in rest-servlet.xml is
              Code:
              	<!-- ========= [ADDED FOR JSON SUPPORT] ========= -->
              	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
              	   <property name="messageConverters">
              	       <list>
              	          	<ref bean="jsonConverter" />
              			<ref bean="marshallingConverter" />
              	       </list>
              	   </property>
              	</bean>
              	
              	<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
              	   <property name="supportedMediaTypes" value="application/json" />
              	</bean>	
              	
              	<bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
              		<constructor-arg ref="jaxbMarshaller" />
              	    <property name="supportedMediaTypes" value="application/xml"/>
              	</bean>
              The relevant code in the Controller (which gets called, verified by the sysout):
              Code:
              	@RequestMapping(method=RequestMethod.GET, value="/locs", headers={"Accept=application/json"})
              	public @ResponseBody LocationList getLocs() {
              		System.out.println("DEBUG: getLocs called");
              		List<Location> locations = locationDS.getAll();
              		LocationList list = new LocationList(locations);
              		return list;
              	}

              The unwanted & unexpected result from the RestClient (useful Firefox plugin to make json and other special calls), with added header Accept=application/json, without this header I get the 405 method not allowed instead (which also is somewhat unexpected, should be 406 WITHOUT the header and working fine with the header).
              Code:
              HTTP Status 406 -
              
              type Status report
              
              message
              
              description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
              Any suggestions or advice are most appreciated.
              Cheers!
              Last edited by Vassago; Jul 18th, 2011, 06:19 AM.

              Comment


              • #8
                No1 has any input or feedback on this issue? I am still baffled by it. Tried removing the Accept headers requirement on the web service method and STILL get the 406 code. There must be something very weird and/or fundamental that is forgotten in the setup somewhere. Any1 has a checklist for these scenarios I could go through to confirm everything is alright.

                Thanks!

                Comment

                Working...
                X