title: Spring 406 not acceptable request from ajax
body: <p>i am getting 406 not acceptable and eating up all my time. I tried a lot, but it not getting solved please help me.</p>
  
  <p><strong>ajax</strong></p>
  
  <pre><code>$('#cls').autocomplete({
                 source: function(request, response) {
                  $.ajax({
                      url: "classes.htm",
                      data: {},
                      contentType: "application/json; charset=utf-8",
                      success: function(data) {
                          alert(data);
                          response(data.names)
                      }
                      ,
                      error:function(jqXHR, textStatus, errorThrown){
                      alert(textStatus);
                      }
                  })
                  }
              });
  </code></pre>
  
  <p><strong>spring controller</strong></p>
  
  <pre><code>@RequestMapping(value="/classes.htm", method = RequestMethod.GET, headers="Accept=*/*")
      public @ResponseBody List&lt;String&gt; getClasses() {
          System.out.println("ajax");
          List&lt;Classes&gt; classes = homeService.getClasses();
          List&lt;String&gt; clsNames = new ArrayList&lt;String&gt;();
          for(Classes cls: classes)
          {
              clsNames.add(cls.getName());
          }
          return clsNames;
      }
  </code></pre>
  
  <p><strong>config xml</strong></p>
  
  <pre><code>&lt;?xml  version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd&gt;
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"&gt;
  
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="org.app.bluez." /&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="classpath:resources/messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" /&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
              &lt;property name="jndiName" value="java:comp/env/jndiName"/&gt;
          &lt;/bean&gt;
  
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:resources/hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="packagesToScan" value="org.app.bluez.domain" /&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven /&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /&gt;  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Now i am getting this error on ajax request. I can see in XHR response like this.</p>
  
  <blockquote>
    <p>HTTP Status 406 -  The resource identified by this request is only
    capable of generating responses with characteristics not acceptable
    according to the request "accept" headers ().</p>
  </blockquote>
  
  <p><strong>the headers</strong></p>
  
  <pre><code>**Response Headers**
  Content-Length  1070
  Content-Type    text/html;charset=utf-8
  Date    Sat, 11 May 2013 21:59:55 GMT
  Server  Apache-Coyote/1.1
  
  **Request Headers**
  Accept  */*
  Accept-Encoding gzip, deflate
  Accept-Language en-US,en;q=0.5
  Connection  keep-alive
  Content-Type    application/json; charset=utf-8
  Cookie  JSESSIONID=DDAC77BE351C26015C6494685E7AC225
  DNT 1
  Host    localhost:8084
  Referer http://localhost:8084/Bluez/register.htm
  User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0
  X-Requested-With    XMLHttpRequest
  </code></pre>
  
  <p>jackson-mapper, jackson-core, jackson jaxrs are also added to project.
  someone please help me out, i have seen similar question here in stackoverflow, the solution was downgrading to spring 3.1, is that true. I am using 3.2 right now..</p>
  
  <p>Thanks and Regards</p>