Java 使用IntelliJ REST客户端测试Spring MVC POST导致415

Java 使用IntelliJ REST客户端测试Spring MVC POST导致415,java,json,spring,spring-mvc,intellij-idea,Java,Json,Spring,Spring Mvc,Intellij Idea,我正在用Java/SpringMVC开发一个应用程序,测试我的GET方法没有问题。出现问题后,我尝试使用@RequestBody测试POST 错误: HTTP 415 The server refused this request because the request entity is in a format not supported by the requested resource for the requested method. 我创建了一个简单的测试来显示我的问题: @Rest

我正在用Java/SpringMVC开发一个应用程序,测试我的GET方法没有问题。出现问题后,我尝试使用@RequestBody测试POST

错误:

HTTP 415 The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
我创建了一个简单的测试来显示我的问题:

@RestController
@RequestMapping("/test")
public class ConcreteTestController implements TestController {

    @RequestMapping(method = RequestMethod.POST)
    @ResponseStatus(value = HttpStatus.OK)
    @Override
    public void add(@RequestBody Dummy dummy) {
        System.out.println(dummy);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseStatus(value = HttpStatus.OK)
    @Override
    public Dummy get() {
        Dummy dummy = new Dummy();
        dummy.setName("apa");
        return dummy;
    }

}
虚拟类非常简单:

public class Dummy {

    private String name;

    public Dummy() {}
    // Omitted setters and getters.
}
GET的jsonresponse如下所示:

{"name":"apa"}
我正在启动IntellijREST客户端,并使用上面的json作为请求主体。我尝试在头中使用application/json和/under-Accept,结果没有任何差异


你知道这是什么原因吗?我被卡住了,非常感谢您的帮助。

默认情况下,您必须在IntelliJ的REST客户端中手动添加内容类型。我忘记了这么做,并将其设置为application/json。这样做之后,它工作得很好