java – 无法在Spring Boot 1.3或1.2.5中设置我的自定义favicon.
几天前我开始使用一个全新的项目FreeMarker第一次使用
Spring Boot 1.3.但是,我正在努力展示我自己的图标.事实上,它在项目的最初阶段运作良好,但几天前,它没有,我无法找到原因.我已经通过stackoverflow上的三个线程谈论它,但没有解决我的问题.我在谷歌搜索但我找不到任何解决方案.
如何重现 试图摆脱这个问题,我已经开始了一个新项目(这次是Spring 1.2.5),我遇到了同样的问题. 项目准备好后,我在demo.web包中创建了HomeController,其中一个测试函数返回“home”.我还在src / main / resources / templates中创建了一个home.ftl,并将两个文件放在src / main / resources / static:demo.png和favicon.ico中(我也尝试将它放在src / main / resources下). demo.png正确显示,但不显示favicon.ico.也许我做错了,因为我是网络开发的新手.
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"; } }
<!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>
<?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> 如果您需要进一步的信息,请问我. 最好的祝福, 编辑 实际上,看起来Spring Boot会覆盖他在资源位置找到的每个favicon.ico. 解决方法
由于@ M.Deinum没有将他的评论作为答案重新发布,我会这样做.
对于Spring Boot 1.3.0.RELEASE,只需将以下行添加到application.properties中: spring.mvc.favicon.enabled = FALSE 根据@Stilleur的说法,至少从Spring Boot 1.3.0.M1开始就有效. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |