Our controller looks like this -
@RestController
@RequestMapping(value="api")
@Validated
public class SampleController {
@RequestMapping(value = {"/test"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void test(
@RequestParam(value = "testCode",required=true) String merchantCode
) throws Exception{
System.out.print("This is Test");
}
}
Here if we do not specify the required parameter "testCode" in our request we get "400 Bad Request", but the message section of the error response remains blank.
Response we are getting -
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"","path":"/test"}
But expected is -
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"Required String parameter 'testCode' is not present","path":"/test"}
We are using below Spring dependencies -
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<spring-framework.version>5.2.6.RELEASE</spring-framework.version>
What I have seen is for this we are getting MissingServletRequestParameterException, but in the exception the message is coming as blank("").
I just updated the bootstrap.yml with server.error.include-message=always
. It appears from Spring 2.3.0 the default behavior of Spring has changed. We can refer the following link from more details https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#changes-to-the-default-error-pages-content
Configuration in application.yml
server:
error:
include-message: always
include-binding-errors: always
include-stacktrace: on_trace_param
include-exception: true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.