Customizing Whitelabel error in Thymeleaf
Spring Boot by default installs a ‘whitelabel’ Error page that you see in a browser client if you encounter a server error. You can customize it as needed based on your view technology, find the below post to override it in thymeleaf.
Step 1: Disable default error page in application.properties
#Disabling Default while lable error server.error.whitelabel.enabled=false
Step 2: Adding a custom error page (error.html)
Overriding the error page with your own depends on the templating technology that you use. Here since I am using Thymeleaf, i have added error.html template.
404 - resource not found 404 - Resource not found
The requested resource was not found; template - specific
Error Info
Status
Step 3: Configure pom.xml
Just add web, thymeleaf starter to your pom or gradle file.
4.0.0 org.springframework.boot spring-boot-starter-parent2.2.8.RELEASE com.candidjava customwhitelabel_error0.0.1-SNAPSHOT customwhitelabel_error Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-thymeleaforg.springframework.boot spring-boot-maven-plugin
Step 4: Launch as Spring boot application (CustomwhitelabelErrorApplication.java)
package com.candidjava.customwhitelabel_error; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class CustomwhitelabelErrorApplication { public static void main(String[] args) { SpringApplication.run(CustomwhitelabelErrorApplication.class, args); } }
This post first appeared on Core Java,Servlet,Jsp,Struts,Hibernate,Spring Fram, please read the originial post: here