Spring Boot - Using Custom Favicon

[Last Updated: Sep 7, 2017]

In Spring Boot application, we can specify a custom favicon by placing favicon.ico (exactly with this name) in any of the static content locations.


Our custom favicon.ico


A MVC controller

public class MyController {

  public String handler(Model model){
      model.addAttribute("msg", "a message from controller");
      return "my-page";

The JSP page


<%@ page language="java"
    contentType="text/html; charset=ISO-8859-1"
    <h2>A JSP page </h2>
    Message : ${msg}

Boot properties


spring.mvc.view.prefix= /WEB-INF/pages/
spring.mvc.view.suffix= .jsp

Main class

public class ExampleMain{

  public static void main(String[] arg) {, arg);

To try examples, run spring-boot maven plugin (configured in pom.xml of example project below):

mvn spring-boot:run


As seen in above screenshot, our custom icon is showing up instead of the default leaf icon.

Example Project

Dependencies and Technologies Used:

  • Spring Boot 1.5.6.RELEASE
    Corresponding Spring Version 4.3.10.RELEASE
  • spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
  • spring-boot-starter-tomcat : Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
  • tomcat-embed-jasper 8.5.16: Core Tomcat implementation.
  • JDK 1.8
  • Maven 3.3.9

Custom Favicon Example Select All Download
  • custom-favicon-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
          • resources
          • webapp
            • WEB-INF
              • pages

    See Also