(Transfer) How to keep static resources from being filtered by the SpringMVC allocator?

The problem is this:
In a SpringMVC project, if the web.xml is configured like this:
   
<servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>
                       org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern> /</url-pattern>
    </servlet-mapping>

The static resources, such as js files, css files, pictures, etc., will be filtered by org.springframework.web.servlet.DispatcherServlet. Of course, DispatcherServlet cannot process these files, so these files will not be sent to the client.

SpringMVC from 3.0.


   
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.XXX.XXX" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    
    <mvc:resources location="/r/" mapping="/r/**" />
    <mvc:annotation-driven />
</beans>



新增的是<mvc:resources location="/r/" mapping="/r/**" />This configuration is equivalent to telling SpringMVC that any request path starting with /r/ will be automatically mapped to the file with the same file name under the r directory without being filtered by DispatcherServlet, so it is done.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327085899&siteId=291194637