acceptable

SpringMVC3.2.x整合Fastjson与Controller单元测试

不羁的心 提交于 2019-12-09 18:09:38
SpringMVC与Fastjson整合相当简单,只要在pom引入fastjson包后,配置一下SpringMVC的messageConverter就可以使用了。 <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"> <mvc:message-converters register-defaults="true"> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"></bean> </mvc:message-converters> </mvc:annotation-driven> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="mediaTypes" > <value> json=application/json xml=application/xml </value> </property> </bean> 但是如果在单元测试时

Spring MVC + JSON = 406 Not Acceptable

僤鯓⒐⒋嵵緔 提交于 2019-12-07 21:27:57
在开发接口时发现了一个很好玩的问题,两个接口均是restful形式,参数在URL路径中传递,返回结果形式均为json,但是在接口测试时,一个接口正常,另一个接口报错:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.本文来分析一下其中的原因。   先介绍一下出错的接口情况,接口代码如下: /** * 验证email是否可用 * @param email * @return */ @ResponseBody @RequestMapping(value = "/emailCheck/{email}", method = RequestMethod.GET) @ApiOperation(value = "验证email是否可用", httpMethod = "GET", response = ApiResult.class, notes = "验证email是否可用") public ApiResult checkEmailValid(@ApiParam(required = true, name = "email",