Announcement Announcement Module
No announcement yet.
Return from getJSON() not being handled? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Return from getJSON() not being handled?

    I am attempting to make use of spring 3 ajax with a simple heartbeat checker. In the jsp I have code that makes the following call:

    function testHeartBeat()
    { $.getJSON( "myApp/StatusCheck?message=Status",
    function( data ) {
    document.getElementById( "heartbeatStatus" ).value = data.response;});}

    The controller which receives this is:

    @RequestMapping(value="/StatusCheck", method=RequestMethod.GET )
    public @ResponseBody HeartBeat getHeartbeat( @RequestParam String message )
    { HeartBeat hb = HeartBeat.Transmit( message );
    return ( hb ); }

    The getHeartbeat is called and returns back a heartbeat object but the callback function in the javascript never runs apparently. I am using <mvc:annotation-driven /> with spring mvc 3.0.5. What I get back is a 406 error: "The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()."

  • #2
    Make sure you have registered the MappingJacksonHttpMessageConverter.

    <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
                <ref bean="jacksonMessageConverter"/>


    • #3
      In the spring-samples the mvc-ajax example, mentioned in the blog article the MappingJacksonHttpMessageConverter was not registered. Does the sample not work then?


      • #4
        According to the documentation, if you have the jackson libraries in the classpath and you use the <mvc:annotation-driven> configuration then it should automatically register the jackson converter for you.


        • #5
          I made sure that the jackson jar is present (jackson-all-1.7.3.jar) along with <mvc:annotation-driven/> When I spin up the server I get the following:

          SEVERE: StandardWrapper.Throwable
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.An notationMethodHandlerAdapter#0': Cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter] while setting bean property 'messageConverters' with key [6]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: (class: org/codehaus/jackson/map/ObjectMapper, method: writeValueAsBytes signature: (Ljava/lang/Object[B) Incompatible argument to function
          at nitionValueResolver.resolveInnerBean(BeanDefinitio
          at nitionValueResolver.resolveValueIfNecessary(BeanDe
          at nitionValueResolver.resolveManagedList(BeanDefinit
          at nitionValueResolver.resolveValueIfNecessary(BeanDe
          at AutowireCapableBeanFactory.applyPropertyValues(Abs
          at AutowireCapableBeanFactory.populateBean(AbstractAu
          at AutowireCapableBeanFactory.doCreateBean(AbstractAu
          at AutowireCapableBeanFactory.createBean(AbstractAuto
          at BeanFactory$1.getObject( 91)
          at ingletonBeanRegistry.getSingleton(DefaultSingleton
          at BeanFactory.doGetBean( )
          at BeanFactory.getBean(
          at istableBeanFactory.preInstantiateSingletons(Defaul
          at ationContext.finishBeanFactoryInitialization(Abstr
          at ationContext.refresh(AbstractApplicationContext.ja va:425)
          at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext( 42)
          at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext( 58)
          at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext( )
          at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(
          at it(
          at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
          at org.apache.catalina.core.StandardWrapper.loadServl et(
          at org.apache.catalina.core.StandardWrapper.allocate(
          at org.apache.catalina.core.StandardWrapperValve.invo ke(
          at org.apache.catalina.core.StandardContextValve.invo ke(
          at org.apache.catalina.core.StandardHostValve.invoke(
          at org.apache.catalina.valves.ErrorReportValve.invoke (
          at org.apache.catalina.core.StandardEngineValve.invok e(
          at org.apache.catalina.connector.CoyoteAdapter.servic e(
          at org.apache.coyote.http11.Http11Processor.process(H
          at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(

          I tried to find the error message on google but came up blank.