我有 :
<context:annotation-config/>
<mvc:annotation-driven/>
在我的 appContext 和我的 pom 中包括 jackson :
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${org.codehaus.jackson-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${org.codehaus.jackson-version}</version>
</dependency>
并且我的控制器@ResponseBody
的返回类型为List<Long>
@RequestMapping(value = "/myUrl/{customerId}/{productId}/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody List<Long> myMethod(@PathVariable Long customerId, @PathVariable Double productId) {
List<Long> result = fieldService.identifyField(customerId, productId);
return result;
}
并且它被单元测试调用(其中 id 是适当的变量):
MockHttpServletRequestBuilder mockHttpServletRequestBuilder
= get("/myUrl/"+customerId+"/"+productId);
MvcResult mvcResult = this.mockMvc.perform(mockHttpServletRequestBuilder)
.andDo(print())
.andExpect(status().isOk())
.andReturn();
请求的打印显示正在找到方法,但是 406,啊!
Handler:
Type = com.mycompany.MyController
Method = public java.util.List<java.lang.Long> uk.co.axiomtechsolutions.ipf.webapp.web.MyController.MyMethod(java.lang.Long,java.lang.Double)
Resolved Exception:
Type = org.springframework.web.HttpMediaTypeNotAcceptableException