arundhaj

regression towards the datascience

HTTP 406 response from spring controller

 

On creating a @ResponseBody annotated spring controller that sends JSON, may lead to "406 Not Acceptable" response though the code/logic works fine.

The cause of this response is because, the controller cannot find the correct HTTPMessageConverter to satisfy the @ResponseBody annotated return value.

Check if, applicationContext.xml file has

<mvc:annotation-driven />

and the following dependency is added to the pom.xml file.

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>1.9.8</version>
</dependency>
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.8</version>
</dependency>

Comments