无法在Spring Boot 1.3或1.2.5中设置我的自定义favicon.ico

Sti*_*eur 3 java favicon spring spring-mvc spring-boot

几天前我开始使用一个全新的项目FreeMarker第一次使用Spring Boot 1.3.但是,我正在努力展示我自己的图标.事实上,它在项目的最初阶段运作良好,但几天前,它没有,我无法找到原因.我已经通过stackoverflow上的三个线程谈论它,但没有解决我的问题.我在谷歌搜索但我找不到任何解决方案.

如何重现

试图摆脱这个问题,我已经开始了一个新项目(这次是Spring 1.2.5),我遇到了同样的问题.使用Spring Tool Suite:新的►SpringStarterProject►然后我勾选了Web和FreeMarker,►完成.

项目准备好后,我在demo.web包中创建了HomeController,其中一个测试函数返回"home".我还在src/main/resources/templates中创建了一个home.ftl,并将两个文件放在src/main/resources/static:demo.pngfavicon.ico中(我也尝试将它放在src/main/resources下).

demo.png正确显示,但不显示favicon.ico.也许我做错了,因为我是网络开发的新手.

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";
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

的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>
Run Code Online (Sandbox Code Playgroud)

如果您需要进一步的信息,请问我.我事先感谢你们的帮助.

最好的问候,Stilleur

编辑

实际上,看起来Spring Boot会覆盖他在资源位置找到的每个favicon.ico.

mir*_*rec 8

请将您重命名favicon.ico为某个不同的ico文件,例如mycustomfavicon.ico.在您的替换正确的名称,href它将工作.