0

我有 :

<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
4

1 回答 1

1

对于其他任何人来说,这似乎是由使用 Double 数据类型作为 Url 变量引起的……句号让 spring 认为它是文件扩展名?将数据类型更改为整数意味着测试通过。

于 2013-10-15T07:44:19.213 回答