Unit testing HttpMediaTypeNotSupportedException在mockmvc post上
我有一个RestController和一个接受post请求的函数Unit testing HttpMediaTypeNotSupportedException在mockmvc post上,unit-testing,spring-boot,mime-types,mockmvc,Unit Testing,Spring Boot,Mime Types,Mockmvc,我有一个RestController和一个接受post请求的函数 @RequestMapping(path = "/auth",method = RequestMethod.POST) public void authenticate(@RequestBody AuthenticationRequest authenticationRequest, HttpServletResponse httpServletResponse) throws IOException { } 我试图发出一个p
@RequestMapping(path = "/auth",method = RequestMethod.POST)
public void authenticate(@RequestBody AuthenticationRequest authenticationRequest, HttpServletResponse httpServletResponse) throws IOException {
}
我试图发出一个post请求
mockMvc.perform(post("/auth")
.contentType(MediaType.APPLICATION_JSON)
.content("{ \"foo\": \"bar\", \"fruit\": \"apple\" }".getBytes()))
.andDo(print());
我收到
Resolved Exception:
Type = org.springframework.web.HttpMediaTypeNotSupportedException
有解决办法吗
编辑:我还尝试在控制器上指定consumes=“application/json”,但仍然不起作用 例外情况是不接受“媒体类型”即“内容类型” 尝试将consumes=“application/json”添加到控制器函数中
@RequestMapping(path = "/auth",method = RequestMethod.POST,consumes = "application/json")
public void authenticate(@RequestBody AuthenticationRequest authenticationRequest, HttpServletResponse httpServletResponse) throws IOException {
}
有关详细信息,请参阅spring文档也许您可以提供整个异常以及更多的上下文?