【发布时间】:2014-12-15 14:56:35
【问题描述】:
我在使用 @RestController 时尝试返回 JSON。我正在使用 Spring 4.1。 这是我在使用 GET 请求调用 listrestsites.html 时遇到的异常。 我的构建路径中有 fastxml Jackson 核心和数据绑定 jar。 @requestheader 接受的输出 = 接受:application/json, text/javascript, /; q=0.01 任何帮助表示赞赏。谢谢,
[DEBUG,ExceptionHandlerExceptionResolver] 解决异常 处理程序 [公共 java.util.List com.amci.spring3.controller.SitesRestController.listRestSites(java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException:不能 找到可接受的表示 [DEBUG,DefaultListableBeanFactory] 返回单例 bean 的缓存实例 'exceptionControllerAdvice' [调试,ExceptionHandlerExceptionResolver] 调用@ExceptionHandler 方法:public org.springframework.web.servlet.ModelAndView
这是我的 Restcontroller 类:
@RestController
public class SitesRestController {
@Autowired
private AssetService assetService;
@RequestMapping("/listrestsites.html")
public List<Asset> listRestSites(@RequestHeader(value="accept") String accept) {
System.out.println(getLogLevel());
System.out.println("accept: " + accept);
return assetService.findAssets();
}
}
另外,我的 spring.xml 中的 sn-p:
<property name="defaultViews">
<list>
<!-- JSON View -->
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
</bean>
</list>
</property>
<property name="ignoreAcceptHeader" value="true" />
</bean>
【问题讨论】:
标签: spring-mvc