I started a fresh new project a couple of days ago using for the first time FreeMarker with Spring Boot 1.3. However, I'm struggling to display my own favicon. In fact, it worked well at the very beginning of the project but since a couple of days ago, it doesn't and I can't find out why. I already get through the three threads on stackoverflow talking about it but none fixed my issue. I searched on Google but I couldn't find any solution.
How to reproduce
Trying to get rid of the problem, I've started a new project (Spring 1.2.5 this time) and I got the same issue. Using Spring Tool Suite : New ► Spring Starter Project ► then I ticked Web and FreeMarker ► Finish.
Once the project ready, I created HomeController in demo.web package with one test function returning "home". I've also created a home.ftl into src/main/resources/templates and put two files in src/main/resources/static : demo.png and favicon.ico (I also tried to place it under src/main/resources).
The demo.png is showing correctly but the favicon.ico is not displayed. Perhaps I'm doing it horribly wrong as I'm a novice in web development.
HomeController.java
package demo.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String get() {
return "home";
}
}
home.ftl
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico">
</head>
<body>
<img src="/demo.png" alt="">
</body>
</html>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
If you need further information please ask me. I thank you all in advance for your help.
Best regards, Stilleur
Edit
Actually, it looks like Spring Boot overrides every favicon.ico he can found in the resource locations.