/ / Réponse JSON du contrôleur REST du printemps - ressort, repos, ressort-mvc, repose-ressort

Réponse JSON du contrôleur REST à ressort - ressort, repose, ressort-mvc, repose-ressort

Je reçois le code d'erreur HTTP 406 avec la description d'erreur suivante:

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

Mon but est d'obtenir ma classe POJO en réponse json. Veuillez trouver mes configurations suivantes:

@RequestMapping(value="/testjson",produces="application/json")
public @ResponseBody Employee testjson () {
System.err.println("testing json");
Employee testEmp = new Employee("1", "Ankit", "Agarwal");

return testEmp;
}

spring-servlet.xml

<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="rss" value="application/rss+xml" />
</map>
</property>
</bean>

Réponses:

0 pour la réponse № 1

essaye ça

@RequestMapping(value="/testjson",produces="application/json",headers = {"Content-type=application/json"})