Spring Boot - Using Custom Favicon

[Updated: Sep 7, 2017, Created: Aug 20, 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-starter-web 1.5.6.RELEASE: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
    Corresponding Spring version: 4.3.10.RELEASE
  • spring-boot-starter-tomcat 1.5.6.RELEASE: Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
    Corresponding Spring version: 4.3.10.RELEASE
  • 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