Custom Favicon in Spring Boot

In this article, we will discuss how to create a custom favicon in Spring Boot application.



A favicon is a small, iconic image that represents your website. Favicons are most often found in the address bar of your web browser. Spring Boot looks for a favicon.ico in the predefined configured place. It also provides options to create a custom favicon for our Spring Boot application.


1. Override Favicon

Spring Boot looks for anfavicon.ico in the configured static content locations and the root of the classpath (in that order). If such a file is present, it is automatically used as the favicon of the application.We can create a custom favicon in Spring Boot application by placing new favicon either in the resource or static directory in our classpath.

Resource Directory


Static Directory


[pullquote align=”normal”]Make sure to name favicon file as “favicon.ico” [/pullquote]


2. Custom Favicon Location

The option 1 is the best and recommended way to create a custom favicon for your Spring Boot application, however, Spring Boot provides an alternate option to completely disable auto scanning process and take complete control using a custom configuration. We can do that by disabling the default favicon in our file.


We add a custom HandlerMapping to do it.

public class FaviconConfiguration {

 public SimpleUrlHandlerMapping faviconHandlerMapping() {
  SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
  return mapping;

 protected ResourceHttpRequestHandler faviconRequestHandler() {
  ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();
   . < Resource > asList(new ClassPathResource("/")));
  return requestHandler;


In the above code, you are free to refer the favicon file at any location.


3. Custom Favicon Controller

Spring Boot provides options to completely disable favicon by setting spring.mvc.favicon.enabled property to false, however, a browser may throw 404 error with the above approach. To handle this issue, create a custom favicon controller.

public void disableFavicon() {
 //Method is void to avoid browser 404 issue by returning nothing in the response.



In this post, we discussed the process to override favicon in the Spring Boot application. We learned how to create a custom favicon in Spring Boot application.