我所有的映射都正常工作:
MvcResult mvcResult = this.mockMvc.perform(get("/company/doSomething"))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
返回状态 ok
@RequestMapping(value = "/company/doSomething", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Boolean myMethod() {
return false;
}
如果我在 Controller 方法中设置一个断点,并运行测试 n Debug模式,测试就会通过(断点不会被调用)并打印出响应 - 没有任何返回,我得到这个:
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = default
Redirected URL = null
Cookies = []
实际请求是这样的
MockHttpServletRequest:
HTTP Method = GET
Request URI = /company/doSomething
Parameters = {}
Headers = {}
Handler:
Type = org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler
最佳答案
从所选的实际处理程序(即 DefaultServletHttpRequestHandler)中,我可以看到没有匹配的带注释的 Controller 方法。不知何故,指定的请求与 Controller 方法请求映射不匹配。
关于java - spring 3.2 测试 requestmappings 在那里并且工作,但是没有调用 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17882817/