I have a simple servlet as follows:
@RestController
public class TestServlet {
@RequestMapping(value = "/test1")
public String test1() {
return "test1";
}
@RequestMapping(value = "/test2")
public String test2(@RequestBody TestClass req) {
return "test2";
}
public static class TestClass {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}
But only the servlet not receiving parameters is working:
Works: http://localhost:8080/test1
Doesn't work: http://localhost:8080/test2?value=1234
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.String
Why is the @RequestBody
annotation not working? Am I missing an important piece?