I want only to edit Spring White Label Page. I see a lot of tutorials for deleting this page, but I want only to change some text here, for example Error 404 - Go back! Any tutorial?
Thanks!
If you are using Spring Boot version 1.4+, custom error pages may be named according to their appropriate error code (e.g. 404.html) and placed in the /src/main/resources/public/error directory for static files or the /src/main/resources/templates/error directory if using a template engine. See Spring Boot and custom 404 error page for more details. You may alternatively follow the steps below to implement custom error pages.
Set the server.error.whitelabel.enabled property to false in your application.properties file. This will disable the error page and show an error page originating from the underlying application container.
server.error.whitelabel.enabled=false
Create custom error pages and save them in resources/templates directory. These pages may be created and named for different HTTP status codes, e.g.: error-404, error-500, etc.
Create a new Controller class that implements the ErrorController interface and override the getErrorPath method. Create a mapping for the path returned by the getErrorPath method. The method that handles this mapping can read the error code and return the appropriate custom error page.
@Controller
public class MyErrorController implements ErrorController {
private static final String ERROR_PATH = "/error";
@RequestMapping("/error")
public String handleError(HttpServletRequest request) {
Object status =
request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
Integer statusCode = Integer.valueOf(status.toString());
if(statusCode == HttpStatus.NOT_FOUND.value()) {
return "error-404";
}
else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()){
return "error-500";
}
}
return "error";
}
@Override
public String getErrorPath() {
return ERROR_PATH ;
}
}