Spring MVC mvc:resources location attribute

前端 未结 4 1475
鱼传尺愫
鱼传尺愫 2020-12-10 21:08

Guys I have also problem with loading static resources.

I think I have everything properly set up. But I don\'t understand location attribute of

相关标签:
4条回答
  • 2020-12-10 21:23

    My Guess is that you're not referencing the location correctly.

    • Is your VAADIN folder inside the WAR's top level directory (in which case location="/VAADIN/" is correct)
    • or is it in WEB-INF/classes (in which case it must be location="classpath:/VAADIN/") ?
    0 讨论(0)
  • 2020-12-10 21:29

    sets up a handler for serving static content. The mapping attribute is set to /resources/**, which includes an Ant-style wildcard to indicate that the path must begin with /resources, but may include any subpath thereof. The location attribute indicates the location of the files to be served. As configured here, any requests whose paths begin with /resources will be automatically served from the /resources folder at the root of the application. Therefore, all of our images, stylesheets, JavaScript, and other static content needs to be kept in the application’s /resources folder.

    0 讨论(0)
  • 2020-12-10 21:33

    Maybe you have configured some handlermapping that kicks in before the resourcehttprequestresolver (or whatever it's called) Check that you don't have an AbstractUrlHandlerMapping or any other handlermapping that stops the mapping chain with an order property. Or configure the resource resolver with an order: <mvc:resources ... order="1" />

    <!-- Maps all other request URLs to views -->
    <bean id="viewMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="defaultHandler">
            <!-- Selects view names to render based on the request URI: e.g. the "/Home" URL would map to the view named "Home" -->
            <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
        </property>
        <!-- This will prevent the mvc:resources to handle requests. Unless, of course, you specify an order in the mvc:resources order attribute
        <property name="order" value="3" /  Removing this will place this just after The ResourceHttpRequestHandler-->
    </bean>
    
    0 讨论(0)
  • 2020-12-10 21:41

    location is the location to the folder where the resources are placed. The XSD docs write:

    The resource location from which to serve static content, specified at a Spring Resource pattern. Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list, and the locations will be checked for a given resource in the order specified. For example, a value of "/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app root and from any JAR on the classpath that contains a /META-INF/public-web-resources/ directory, with resources in the web app root taking precedence.

    On the other hand, the mapping attribute is:

    The URL mapping pattern, within the current Servlet context, to use for serving resources from this handler, such as "/resources/**"

    So mapping specifies under what uri will resources be accessible on the web, while location specifies where are these resources located on the disk.

    0 讨论(0)
提交回复
热议问题