0
でサポートされていないメディアタイプIが4.2.4にバージョン3(XMLベース)から春をアップグレードしています(注釈ベース)エラー415 - 春4
コントローラ
@RestController
public class XnetOrderResourceController{
@Autowired
private XnetOrderDao orderDao;
/*
* GET All Orders
*/
@RequestMapping(value = "/getAllOrdersInfo", method =RequestMethod.GET, produces="application/json")
public XnetOrder get(@RequestParam("Id") Long Id) {
XnetOrder order=null;
try{
if(MiscUtils.isNotEmpty(Id)){
order=orderDao.get(Id);
}
}catch(HibernateException e){
log.info(ORDER_DETAIL_NOT_AVAILABLE);
getLogger().error(e.getMessage());
}
return order;
}
/*
* POST(create new) Orders
*/
@RequestMapping(value = "/insertOrders", method =RequestMethod.POST, consumes="application/json", produces="application/json")
public void post(@RequestBody XnetOrder order){
try{
orderDao.post(order);
}catch(HibernateException e){
log.info("Creating the Order operation failed.");
getLogger().error(e.getMessage());
}
}
/*
* PUT (update) orders
*/
@RequestMapping(value="/updateOrders", method=RequestMethod.PUT, consumes="application/json", produces="application/json")
public XnetOrder update(@RequestBody XnetOrder order){
try{
order=orderDao.put(order);
}catch(HibernateException e){
getLogger().error(e.getMessage());
}
return order;
}
/*
* DELETE orders
*/
@RequestMapping(value="/deleteOrders",method=RequestMethod.DELETE)
public void delete(@RequestParam("Id") Long Id){
try{
if(MiscUtils.isNotEmpty(Id)){
orderDao.delete(Id);
log.info("Order is successfully deleted");
}
}catch(HibernateException e){
log.info(XNET_PRODUCT_INVALID_ERROR_MESSAGE);
getLogger().error(e.getMessage());
}
}
}
私のクラスパスに個のSpring-Servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="com.nest.extranet" />
<mvc:annotation-driven
content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
<property name="favorParameter" value="true" />
<property name="mediaTypes">
<value>
json=application/json
</value>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
JARファイルがある -
jackson-annotations-2.2.3.jar,
jackson-core-2.2.3.jar,
jackson-databind-2.3.3.jar,
jackson-mapper-asl-1.9.13.jar,
jackson-2.1.0-all.jar
私は成功したJSON値を返しますが、PUT
とPOST
操作は動作しませんGET
操作を行うことが可能です。私はRESTクライアントとしてPostmanを使用しています。私はまた、aplication/json
にヘッダー値Content-Type
を設定した後PUT
操作のためのURLを渡してみましたが、それは常に
エラー415を返します - サポートされていないメディアタイプを。
私は、次の応答ヘッダを取得しています:
Connection → close
Content-Length → 903
Content-Type → text/html; charset=UTF-8
Date → Sat, 14 May 2016 09:16:57 GMT
X-Powered-By → Servlet/2.5 JSP/2.1
誰かがPUT
とPOST
操作作業を取得する方法を提案してくださいことはできますか?
私は試してみましたが、消費するだけです。同じ問題がまだ残っています。コントロールはメソッドを更新することはありません。 –
URLに '?format = json'を追加してみてください。それがうまくいくなら、あなたのコンテンツネゴシエーションマネージャは物事を乱しています。人々は、通常、ネゴシエーションマネージャを使用するアノテーションで消費/生産を指定するか、両方を使用することを指定しない –