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.
Example
Our custom favicon.ico
src/main/resources/favicon.ico
A MVC controller
@Controller
public class MyController {
@RequestMapping("/app")
public String handler(Model model){
model.addAttribute("msg", "a message from controller");
return "my-page";
}
}
@SpringBootApplication
public class ExampleMain{
public static void main(String[] arg) {
SpringApplication.run(ExampleMain.class, arg);
}
}
To try examples, run spring-boot maven plugin (configured in pom.xml of example project below):
mvn spring-boot:run
Output
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.