Below is my controller method definition
@Autowired
private HttpServletRequest request;
@PostMapping(path = "/abc")
public String createAbc(@RequestBody HttpServletRequest request)
throws IOException {
logger.info("Request body: "+request.getInputStream());
return "abc";
}
All i want to do is print contents to request body. But when i make a POST request i see below error:
Type definition error: [simple type, class javax.servlet.http.HttpServletRequest]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
javax.servlet.http.HttpServletRequest
(no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 2]",
I'm using Spring boot 2.x version.Any idea what's wrong in my code?
autowired
your request. Where did you get@RequestBody HttpServletRequest request
from ? – Erlene