1
我有一個RestController並接受POST請求的功能HttpMediaTypeNotSupportedException上mockmvc後
@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」,但仍然不起作用。
我試了一下春天的文檔,但它給出了同樣的異常。 – gkatzioura
也許你可以用更多的上下文來提供整個異常? –