How to Manage and Customize Favicon in Spring Boot 2.x
This guide explains how Spring Boot handles favicon across versions, how to disable the default icon, and provides step‑by‑step instructions for adding a custom favicon—including Thymeleaf integration, cache clearing tips, and troubleshooting common issues.
Favicon handling in Spring Boot
Early Spring Boot releases automatically served a default favicon.ico. It could be disabled with the property spring.mvc.favicon.enabled=false. Starting with Spring Boot 2.2 the built‑in favicon was removed and the property no longer exists. See issue https://github.com/spring-projects/spring-boot/issues/17925.
Adding a custom favicon
Place your favicon.ico file in src/main/resources/static (or directly under src/main/resources). Spring Boot will serve it automatically at the URL /favicon.ico.
After updating the file, clear the browser cache or restart the browser to ensure the new icon is loaded.
Reference in HTML pages
Thymeleaf template example:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Hello Favicon</title>
<link rel="icon" th:href="@{/favicon.ico}" type="image/x-icon"/>
<link rel="bookmark" th:href="@{/favicon.ico}" type="image/x-icon"/>
</head>
<body>
<h1>Hello Favicon!</h1>
</body>
</html>Plain HTML example (no Thymeleaf):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Hello Favicon</title>
<link rel="icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="bookmark" href="/favicon.ico" type="image/x-icon"/>
</head>
<body>
<h1>Hello Favicon!</h1>
</body>
</html>Adding the <link rel="icon" ...> tags is required only for pages that need an explicit reference.
Verification and troubleshooting
Directly open http://localhost:8080/favicon.ico in a browser; a successful response confirms the server is serving the icon.
Typical problem: browser cache or Thymeleaf template cache prevents the updated favicon from appearing.
If a custom interceptor, filter, or security configuration blocks static resources, the request may return 404. Review such components when the icon is not reachable.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
