java - Spring @ResponseBody View 解析

标签 java spring model-view-controller

问题

有人找到了 @ResponseBody 的 View 解析的替代方法(以允许实现 ConcentNegotiatingViewResolver 的部分功能)吗?

推理

spring View 解析机制非常强大,特别是ContentNegotiatingViewResolver ,允许 View 解析,例如在路径扩展 (foo.json) 或请求参数 (?view=json) 上。

但是,当使用@ResponseBody注释时, View 解析链被绕过。与mvc:annotation-driven我们得到一个RequestMappingHandlerAdapter相反, View 分辨率似乎仅基于 Accept header 。

最佳答案

原来Spring的英雄们已经注意到这个问题了#SPR-8410#SPR-7517

This is now resolved. To configure, declare a ContentNegotiationManager bean with a ParameterContentNeogiationStrategy and use it in turn to configure RequestMappingHandlerMapping, RequestMappingHandlerAdapter and ExceptionHandlerExceptionResolver.

修复版本3.2 M2

关于java - Spring @ResponseBody View 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12978074/

相关文章:

java - 如何使用spring AOP切入点表达式拦截返回类型List

jquery - AJAX 请求格式错误?问题出在哪里?

json - 从 json 到枚举的 Mvc 绑定(bind)问题(从 int 到枚举的自定义异常)

java - Spring BeanUtils 无法实例化泛型类

java - Java EE 5 中的两阶段提交事务

java - Actionbar Overflow 中的单元测试菜单项

java - 如何在从 A "Super"接口(interface)扩展的接口(interface)方法上创建方面

java - 什么代表 Spring MVC 中 ResponseEntity 对象的 HttpStatus?

Spring Security 何时使用 WebSecurityConfigurerAdapter 和 UserDetailsS​​ervice

objective-c - 独立的委托(delegate)和 Controller