Skip to content

Rework ErrorController now that getErrorPath() is unused and server.error.path must be used to configure the error path #19844

@brucebrit

Description

@brucebrit

Spring boot: 2.2.2
IDE: Spring Tool Suite

One of the ways to create a custom error page is to create a controller class that implements ErrorController. By overriding the getErrorPath() method and returning /error, I am able to return the expected my custom error page (located at resources/templates/customError.html).

But when I return another path, other than /error, I get the following error:

This localhost page can’t be found. No webpage was found for the web address: http://localhost:8080/bruce

Why is that so.

@Controller
public class MyErrorController implements ErrorController{

 // @RequestMapping("/error")
    @RequestMapping("/error1")
    public String handleError() {
        return "customError";
    }

	@Override
    public String getErrorPath() {

        //return "/error"; 
        return "/error1"; 
    }
}

Interestingly, I have done another experiment. The getErrorPath() returns /error1 , but I change the RequestMapping annotation to @RequestMapping("/error"), and that really return customError.html. This seems to imply that the path return by getErrorPath() is ignored.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions