3
可以說我的控制器中有兩種方法支持json和xml。爲什麼Spring消息轉換器仍然在@Cachable方法中調用
@RequestMapping(value = "/get/response.json", method = RequestMethod.GET)
@Cacheable(JSON_CACHE)
public @ResponseBody JSONResponse getJsonResponse(){
return responseService.getJsonResponse();
}
@RequestMapping(value = "/get/response.xml", method = RequestMethod.GET)
@Cacheable(XML_CACHE)
public @ResponseBody XMLResponse getXmlResponse(){
return responseService.getXmlResponse();
}
和兩個消息轉換器,將我的對象編組爲合適的響應。
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter"/>
<ref bean="xmlConverter" />
</list>
</property>
</bean>
的問題在於春3.1,即使方法都添加了@Cachable
,仍引發編組爲每個呼叫。它在編組之前緩存對象的狀態。 這是不可接受的,因爲性能在這裏至關重要,編組對我來說太昂貴了。我預計Spring會在這種情況下緩存最終響應。我在這裏做錯了什麼?