Spring MVC mvc:资源位置属性 [英] Spring MVC mvc:resources location attribute
问题描述
伙计们,我在加载静态资源时也遇到了问题.
Guys I have also problem with loading static resources.
我认为我已经正确设置了所有内容.但是我不理解 mvc:resources 的 location 属性.有什么用?
I think I have everything properly set up. But I don't understand location attribute of mvc:resources. What is it for?
如果我的静态资源位于位置VAADIN/themes/theme/...(在几个子文件夹,图像,css,js中),则位置和映射属性的正确值应该是什么?
if I have my static resources under location VAADIN/themes/theme/... (in several subfolders, images, css, js) what should be the correct values for location and mapping attributes?
当我进行以下配置时:
<mvc:resources location="/VAADIN/" mapping="/VAADIN/**"/>
它不起作用.我想日志的以下部分是相关的:
it doesn't work. I suppose the following part of log is related:
17:15:02.897 [http-8080-2] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#6': no
URL paths identified
例如,我收到 HTTP状态404 . http://127.0.0.1/VAADIN/themes/theme/css/style.css
推荐答案
location
是放置资源的文件夹的位置. XSD文档写道:
location
is the location to the folder where the resources are placed. The XSD docs write:
在Spring Resource模式下指定从其提供静态内容的资源位置. 每个位置必须指向一个有效目录.可以将多个位置指定为以逗号分隔的列表, 并将按照指定的顺序检查给定资源的位置.例如,值为 "/,类路径:/META-INF/public-web-resources/"将允许同时从Web应用程序提供资源 根目录,以及来自包含/META-INF/public-web-resources/目录的类路径上的任何JAR, Web应用程序根目录中的资源优先.
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.
另一方面,mapping
属性是:
当前Servlet上下文中的URL映射模式,用于从该处理程序中提供资源,例如"/resources/**"
The URL mapping pattern, within the current Servlet context, to use for serving resources from this handler, such as "/resources/**"
因此mapping
指定在网络上可以访问哪些uri,而location
指定这些资源在磁盘上的位置.
So mapping
specifies under what uri will resources be accessible on the web, while location
specifies where are these resources located on the disk.
这篇关于Spring MVC mvc:资源位置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!