Introduction
In Spring Web MVC 6, to show error of REST response in RFC9457 format is supported out of the box. Following is the example of location not found error message.
To enable it, just add a line into application.properties.
spring.mvc.problemdetails.enabled=true
So, a problemDetailsExceptionHandler bean (class org.springframework.boot.autoconfigure.web.servlet.ProblemDetailsExceptionHandler) will be created. This bean is for constructing the response JSON from Exception instance which is a child class of jakarta.servlet.ServletException. For example, if no handler can be found of a request, a org.springframework.web.servlet.NoHandlerFoundException will be thrown.
Top comments (0)