ptimson ptimson - 2 months ago 89
Java Question

Spring Boot Disable /error mapping

I am creating an API with Spring Boot so wish to disable the


I have set the following props in


However when I hit
I get:

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 03 Aug 2016 15:15:31 GMT
Connection: close

{"timestamp":1470237331487,"status":999,"error":"None","message":"No message available"}

Required Result

HTTP/1.1 404 Internal Server Error
Server: Apache-Coyote/1.1


You can disable the ErrorMvcAutoConfiguration :

@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class SpringBootLauncher {

Or through Spring Boot's application.yml/properties:

spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration

If this is not an option for you, you may also extend Spring's ErrorController with your own implementation:

public class MyErrorController implements ErrorController {

    private static final String ERROR_MAPPING = "/error";

    @RequestMapping(value = ERROR_MAPPING)
    public ResponseEntity<String> error() {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);

    public String getErrorPath() {
        return ERROR_MAPPING;