How to Manage Favicon in Spring Boot 2.x: Disable Default Icon and Add a Custom One
This article explains how Spring Boot 2.x handles favicons, why the default icon can expose framework details, how to disable it, and provides step‑by‑step instructions and code snippets for adding a custom favicon using Thymeleaf or plain HTML while addressing common caching issues.
Normally each website has a favicon that appears on the browser tab.
Spring Boot provides default favicon support, but different versions behave differently; many articles are outdated, so this article examines the situation in Spring Boot 2.x.
Spring Boot version support for favicon
Earlier versions enabled favicon by default and allowed disabling with the property: spring.mvc.favicon.enabled=false ## disable When enabled, the default icon is shown as below:
However, providing a default favicon can leak information about the framework used.
Since Spring Boot 2.2.x the default favicon.ico has been removed and the related property no longer exists. See the issue https://github.com/spring-projects/spring-boot/issues/17925 for details.
Custom favicon
To use a custom favicon, place a file named favicon.ico in the resources or static directory. Ensure browser cache is cleared.
If you need to reference it in pages, the following Thymeleaf example can be used:
<!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>For other front‑end frameworks you can use a similar approach:
<!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>Notes
The most common issue is caching (Thymeleaf cache, browser cache). If the icon does not appear, clear caches or directly access http://localhost:8080/favicon.ico to verify.
Custom web components or interceptors may also block the favicon, so check them if a 404 occurs.
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.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
