A favicon is the small icon that a browser shows in the tab, in the bookmarks and in the history. In a Spring Boot application, we can use a custom favicon by placing a file named favicon.ico (exactly this name) in any of the static content locations. The most common location is src/main/resources/static.
plugins {
java
id("org.springframework.boot") version "4.2.0"
id("io.spring.dependency-management") version "1.1.7"
}
println(">>> EXECUTING SCRIPT: build.gradle.kts (Kotlin DSL)")
group = "com.logicbig.example"
version = "1.0-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_25
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
}
plugins {
id 'java'
id 'org.springframework.boot' version '4.2.0'
id 'io.spring.dependency-management' version '1.1.7'
}
println ">>> EXECUTING SCRIPT: build.gradle (Groovy DSL)"
group = 'com.logicbig.example'
version = '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_25
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
Our custom favicon.ico
src/main/resources/static/favicon.ico
A Spring MVC controller
package com.logicbig.example;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/app")
public String handler(Model model){
return "Response from a Spring Controller";
}
}
Main class
package com.logicbig.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ExampleMain {
public static void main(String[] arg) {
SpringApplication.run(ExampleMain.class, arg);
}
}
2026-11-24T21:26:03.281-06:00 INFO 27936 --- [ main] com.logicbig.example.ExampleMain : Starting ExampleMain using Java 25 with PID 27936 (D:\LogicBig\example-projects\spring-boot\custom-favicon-example\target\classes started by joe2 in D:\LogicBig\example-projects\spring-boot\custom-favicon-example) 2026-11-24T21:26:03.286-06:00 INFO 27936 --- [ main] com.logicbig.example.ExampleMain : No active profile set, falling back to 1 default profile: "default" 2026-11-24T21:26:04.101-06:00 INFO 27936 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2026-11-24T21:26:04.116-06:00 INFO 27936 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2026-11-24T21:26:04.117-06:00 INFO 27936 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.27] 2026-11-24T21:26:04.166-06:00 INFO 27936 --- [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 826 ms 2026-11-24T21:26:04.533-06:00 INFO 27936 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/' 2026-11-24T21:26:04.540-06:00 INFO 27936 --- [ main] com.logicbig.example.ExampleMain : Started ExampleMain in 1.662 seconds (process running for 1.93)
In above example, we ran the main class directly from IntelliJ IDEA. Alternatively, you can execute it from the command line using your build tool:
Maven:mvn spring-boot:run
Gradle:gradle bootRun
Output on Browser
As we can see in the screenshot, our custom icon is shown in the browser tab.
How does it work?
Spring Boot does not have any special code for favicons in current versions. The browser asks the server for /favicon.ico, and the normal static resource handling serves the file. This works because static is one of the default static content locations (the others are /public, /resources and /META-INF/resources on the classpath).
Checking the Chrome Network tab in DevTools (invoked via F12):
Chrome follows a standard fallback rule: whenever a page doesn't specify an icon in HTML (via a link tag, see next paragraph), the browser automatically makes a second, separate request to /favicon.ico to populate the tab titlebar.
Using a link tag
A browser asks for /favicon.ico on its own, but it is better to tell it clearly with a link tag inside the head of the page. This also lets us use another file name or another format (like PNG or SVG):
<link rel="icon" href="/favicon.ico"/>
What happens if our application uses a context path (e.g. /abc). The browser's automatic request goes to the server root (/favicon.ico), not to /abc/favicon.ico, so the automatic lookup misses our application. In this case, the link tag must include the context path. In a JSP page, we can write:
In Thymeleaf we include context path as: @{/favicon.ico}
Browsers cache favicons very strongly. If we replace the icon and still see the old one, we should do a hard refresh or open the page in a private window.
Output in curl
Curl Output
$ curl -s "http://localhost:8080/app" Response from a Spring Controller
How favicons work in Spring Boot changed a lot in the past:
Spring Boot 1.x to 2.1: Boot had its own favicon handler. It looked for favicon.ico in the root of the classpath first (for example src/main/resources/favicon.ico) and then in the static content locations. If we did not provide a favicon, Boot showed its own default green leaf icon. We could turn this feature off with spring.mvc.favicon.enabled=false.
Spring Boot 2.2 and later: The default leaf icon, the special favicon handler and the property were removed. One reason was that the default icon showed that the application was built with Spring Boot, which is a kind of information leak. The property spring.mvc.favicon.enabled has no effect anymore, so we should not use it. Now only the normal static resource handling is left. This means favicon.ico must be in a static content location (like src/main/resources/static). The root of the classpath is not a static content location, so the old place src/main/resources/favicon.ico does not work anymore. If there is no favicon, the browser shows its own default icon, or a "404 Not Found" is logged for the request.
Example Project
Dependencies and Technologies Used:
Spring Boot 4.2.0 Corresponding Spring Framework Version 7.1.0 Version Compatibility: 2.0.0.RELEASE - 4.2.0Version List
×
Version compatibilities of spring-boot-starter-parent with this example:
2.0.0.RELEASE
2.0.1.RELEASE
2.0.2.RELEASE
2.0.3.RELEASE
2.0.4.RELEASE
2.0.5.RELEASE
2.0.6.RELEASE
2.0.7.RELEASE
2.0.8.RELEASE
2.0.9.RELEASE
2.1.0.RELEASE
2.1.1.RELEASE
2.1.2.RELEASE
2.1.3.RELEASE
2.1.4.RELEASE
2.1.5.RELEASE
2.1.6.RELEASE
2.1.7.RELEASE
2.1.8.RELEASE
2.1.9.RELEASE
2.1.10.RELEASE
2.1.11.RELEASE
2.1.12.RELEASE
2.1.13.RELEASE
2.1.14.RELEASE
2.1.15.RELEASE
2.1.16.RELEASE
2.1.17.RELEASE
2.1.18.RELEASE
2.2.0.RELEASE
2.2.1.RELEASE
2.2.2.RELEASE
2.2.3.RELEASE
2.2.4.RELEASE
2.2.5.RELEASE
2.2.6.RELEASE
2.2.7.RELEASE
2.2.8.RELEASE
2.2.9.RELEASE
2.2.10.RELEASE
2.2.11.RELEASE
2.2.12.RELEASE
2.2.13.RELEASE
2.3.0.RELEASE
2.3.1.RELEASE
2.3.2.RELEAS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.5.16
4.0.0
4.0.1
4.0.2
4.0.3
4.0.4
4.0.5
4.0.6
4.0.7
4.0.8
4.0.9
4.0.10
4.1.0
4.1.1
4.1.2
4.1.3
4.2.0
Versions in green have been tested.
spring-boot-starter-web (Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container (deprecated in favor of spring-boot-starter-webmvc))