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

abi*_*eez 13 spring-mvc

我不记得我的代码有什么变化,但每当我点击网络上的任何链接时,它都会给我这样的信息:

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

我的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>
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

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

and*_*dyb 19

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

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

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