Spring mvc:资源找不到*.ico文件

Roo*_*osh 13 java favicon spring spring-mvc ico

我很难让我的Spring 3.0应用程序将favicon.ico类型文件识别为资源.我在我的spring-context.xml文件中定义了我的资源目录,如下所示:

<mvc:resources mapping="/ui/**" location="/ui/" />
Run Code Online (Sandbox Code Playgroud)

此目录结构如下所示:

/ui
  /images
  /styles
  /scripts
  ...
Run Code Online (Sandbox Code Playgroud)

Spring可以很好地托管我的图像,脚本和样式.但是,尝试检索*.icoimages目录中的任何文件时出现404错误.所有PNG,GIF和JPG图像在同一目录中都可以正常工作.我尝试更具体地说明要托管哪些目录,甚至指定.ico文件作为文件中的资源context.xml,仍然得到相同的结果:

<mvc:resources mapping="/ui/images/*.ico" location="/ui/images" />
Run Code Online (Sandbox Code Playgroud)

我也尝试将servlet映射添加到默认的servlet.当我在网上进行研究时,这似乎对某些人有用,但对我来说并没有证明是成功的.

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.ico</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

编辑:我还将favicon.ico文件添加到Web应用程序的根路径.如果我使用一个png文件作为favicon,它适用于每个浏览器,但IE.如果可能的话,我想为所有浏览器解决这个问题.在这一点上任何帮助将不胜感激.

EDIT2:我已经在XHTML文档中有一个链接标记:

<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/ui/images/favicon.ico" />
Run Code Online (Sandbox Code Playgroud)

Roo*_*osh 14

我使用Tomcat 6来托管应用程序的解决方案是将MIME类型添加到应用程序的web.xml文件中,如下所示.

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

谢谢skaffman!