I have a small issue, in development I created an API that also checks if the POST values are valid with annotation @Valid.
@PostMapping("/news")
@ResponseBody
public News add(@Valid @RequestBody News news){
return repository.save(news);
}
When the fields are invalid, I get a return with the errors included, with the fields and defaultMessage.
I have an entity with annotations like @NotBlank etc.
Once I build my project to a jar file, and I run my project with this file, I do not get those errors anymore included in the response.
I was taking maybe this is because of development mode or something but I couldn't find anything online about it.
CodePudding user response:
I assume that you are using Spring Boot's Devtools. They enable the inclusion of binding errors by default. This is only done at development time to reduce the risk of information leakage in your application's error responses. If you're comfortable with this risk, you can enable the behaviour by adding server.error.include-binding-errors = always
to application.properties
.