Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring mvc:resource not finding *.ico files

I have had a really hard time getting my Spring 3.0 application to recognize favicon.ico type files as a resource. I have defined my resource directory in my spring-context.xml file as follows:

<mvc:resources mapping="/ui/**" location="/ui/" />

This directory structure looks like:

/ui
  /images
  /styles
  /scripts
  ...

Spring hosts my images, scripts, and styles just fine. However, I get a 404 error when trying to retrieve any *.ico files in the images directory. All PNG, GIF, and JPG images work just fine in that same directory. I tried being more specific on which directories to host and even specified .ico files as resources in the context.xml file and still get the same results:

<mvc:resources mapping="/ui/images/*.ico" location="/ui/images" />

I've also tried adding a servlet mapping to the default servlet. This seemed to work for some when I researched online, but has not proven successful for me.

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.ico</url-pattern>
</servlet-mapping>

EDIT: I have also added the favicon.ico file to the root path of the web app. If I use a png file for the favicon, it works in every browser but IE. I would like to solve this problem for all browsers if possible. Any help at this point would be greatly appreciated.

EDIT2: I already have a link tag in the XHTML document:

<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/ui/images/favicon.ico" />
like image 472
Roosh Avatar asked Mar 10 '11 15:03

Roosh


1 Answers

The solution for me, since I was using Tomcat 6 to host the application, was to add the MIME type to the web.xml file of the application as shown below.

<mime-mapping>
    <extension>ico</extension>
    <mime-type>image/vnd.microsoft.icon</mime-type>
</mime-mapping>

Thanks skaffman!

like image 64
Roosh Avatar answered Oct 22 '22 18:10

Roosh