为什么在 post、mvc 测试中出现此 415 响应?

Why this 415 response in a post, mvc test?

希望有人能提供帮助。我一直在关注这个 [在线资源][1],试图为 RestController 编写集成测试:

@Test
public void obfiscated() throws Exception {
    SearchRequest autoCompleteSearchrequest = new SearchRequest();
    autoCompleteSearchrequest.setCity("somewheresville");
    

尝试将 consumes = MediaType.APPLICATION_JSON_VALUE 添加到您的 RequestMapping

尽管我认为这是由 @SpringBootTest 注释处理的,但我认为这是错误的;我采纳了在另一个问题中找到的建议,并在 class 级别为我的测试添加了 @EnableWebMvc,并修复了它。