你需要将代码更改为以下内容:
@RestControllerpublic class IndexController implements ErrorController{ private static final String PATH = "/error"; @RequestMapping(value = PATH) public String error() { return "Error handling"; } @Override public String getErrorPath() { return PATH; }}你的代码无法正常工作,因为
BasicErrorController当你未指定的实现时,Spring Boot会自动将其注册为
Spring Bean ErrorController。
要查看该事实,请导航至
ErrorMvcAutoConfiguration.basicErrorController此处。



