找不到带URI的HTTP请求的映射[/favicon.ico]

时间:2013-06-11 04:13:59

标签: spring-mvc

我无法回想起我的代码有什么变化,但每当我点击网络上的任何链接时,它都会给我这个:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/favicon.ico] in DispatcherServlet with name 'mvc-dispatcher'

我的web.xml的一部分

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter>
    <filter-name>HttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

我的mvc-dispatcher-servlet.xml的一些配置

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/**" location="resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
        <beans:property name="order" value="1" />
    </beans:bean>
    <!-- testing for pdf export -->
    <beans:bean class="org.springframework.web.servlet.view.XmlViewResolver">
        <beans:property name="location" value="/WEB-INF/spring-pdf-views.xml" />
        <beans:property name="order" value="0" />
    </beans:bean>

除此之外一切正常,意味着任何页面都正确加载而没有任何错误。我可以知道是什么原因造成的吗?谁正在使用.ico图片?

3 个答案:

答案 0 :(得分:19)

大多数网络浏览器都会尝试在上下文的根目录中获取网站的favicon,并自动请求/favicon.ico资源 。在您的情况下,任何配置的Spring映射都不会处理。

如果您在/favicon.ico或其他位置有一个favicon,您可以在Spring中配置映射以解析对有效资源的请求:

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

答案 1 :(得分:0)

浏览器标签中的favicon.ico:图标

由于Spring Security正在使用

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

您是否将favicon.ico排除在Spring Security的过滤之外?

<http pattern="/favicon.ico" security="none" />

答案 2 :(得分:0)

尝试在html页面中找到favicon.ico,如下所示:

<html>
    <head>
      <link href="[YOUR_FAVICON_PATH]/favicon.ico" rel="icon" type="image/x-icon" />
    </head>
</html>
相关问题