java spring spring-boot spring-mvc thymeleaf

Spring Boot and custom 404 error page

In my Spring Boot application, I’m trying to configure custom error pages, for example for 404, I have added a following Bean to my application configuration:

public EmbeddedServletContainerCustomizer containerCustomizer() {
return new EmbeddedServletContainerCustomizer() {
public void customize(ConfigurableEmbeddedServletContainer container) {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));

Also, I have created a following simple Thymeleaf template:

<!DOCTYPE html>
<html xmlns="" xmlns:th="">
<title>404 Not Found</title>
<meta charset="utf-8" />
<h3>404 Not Found</h3>
<h1 th:text="${errorCode}">404</h1>
<p th:utext="${errorMessage}">Error java.lang.NullPointerException</p>
<a href="" th:href="@{/}">Back to Home Page</a>

and added it into /resources/templates/ folder. Right now on the 404 error I can see only white screen.

What am I doing wrong and how to correctly setup my 404 page? Also, is it possible to use templates and not only static pages for custom error pages?