favicon.ico 在 spring mvc 中不显示

Mik*_*ike 5 java favicon spring-mvc

我正在尝试使用 spring mvc 4 和 apache tomcat 7 (在 firefox 中)添加 favicon.ico。我检查了许多解决方案,但似乎没有一个有效。

网络.xml:

<mime-mapping>
    <extension>ico</extension>
    <mime-type>image/x-icon</mime-type>
</mime-mapping>
Run Code Online (Sandbox Code Playgroud)

mvc-core-config.xml:

<mvc:default-servlet-handler/>
<!-- <mvc:resources mapping="/resources/**" location="/resources/css" /> -->
<mvc:resources location="/favicon.ico" mapping="/favicon.ico" />
Run Code Online (Sandbox Code Playgroud)

jsp:

<link href="MYPROJECT/favicon.ico" rel="icon" type="image/x-icon">
Run Code Online (Sandbox Code Playgroud)

(我也尝试过没有 MYPROJECT 和其他变体......)。

我将 favicon.ico 文件放在 webapps 下(也在其他文件夹中尝试过)。

加载页面时,没有显示任何图标。

注意:我尝试直接加载图标http://localhost:8080/MYPROJECT/favicon.ico,但收到以下错误消息:the image 'http://localhost:8080/MYPROJECT/favicon.ico' cannot be displayed because it contains errors。我下载了其他 favicon.ico,但图标看起来已损坏。

在 Firefox 中检查元素时,我不会调用 favicon.ico。

有什么建议吗?

更新: 在我的 Eclipse 控制台中我看到:

查找路径 / 15:48:05.622 [http-bio-8080-exec-6] 的处理程序方法 DEBUG oswsmmaRequestMappingHandlerMapping - 未找到 [/] 15:48:05.622 [http-bio-8080-exec-6] 的处理程序方法] DEBUG oswsmmaRequestMappingHandlerMapping - 查找路径 / 15:48:05.623 的处理程序方法 [http-bio-8080-exec-6] DEBUG oswsmmaRequestMappingHandlerMapping - 未找到 [/] 15:48:05.623 [http-bio-8080] 的处理程序方法-exec-6] DEBUG oswshSimpleUrlHandlerMapping - 使用处理程序 [org.springframework.web.servlet.mvc.ParameterizedViewController@380baa3a] 和 1 个拦截器映射 [/] 到 HandlerExecutionChain

更新2 mvc配置xml:

<import resource="mvc-view-config.xml"/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>     
<mvc:annotation-driven conversion-service="conversionService"/>   
<context:component-scan base-package="controllers,logic.preprocess"/>
<mvc:view-controller path="/" view-name="index" />
<mvc:default-servlet-handler/>

<mvc:resources location="/favicon.ico" mapping="/favicon.ico" />

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
    p:basename="messages/messages"/>

</beans>
Run Code Online (Sandbox Code Playgroud)

包含的mvc-view-config.xml:

<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="viewResolvers">
        <list>
            <bean
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
                <property name="prefix" value="/WEB-INF/jsp/" />
                <property name="suffix" value=".jsp" />
                <property name="contentType" value="text/html;charset=UTF-8"></property>
            </bean>


<bean       class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order" value="1"/> </bean>

 <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" /> </bean>

 <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
     <property name="order" value="3" />
     <property name="alwaysUseFullPath" value="true" />
     <property name="mappings">
     <props>
         <prop key="controllers/TaskController">taskController</prop>
         <prop key="controllers/ResultController">resultController</prop>
     </props>
     </property>
 </bean>
Run Code Online (Sandbox Code Playgroud)

update 3 我将文件放在资源/图像下,它似乎只能在 chrome 上部分工作(没有快捷方式),但不能在 firefox 上工作。

谢谢,迈克

小智 1

存储 favicon.ico - WEB-INF 目录中的一个。

 <link href="/favicon.ico" rel="icon" type="image/x-icon">
Run Code Online (Sandbox Code Playgroud)