Spring MVC mvc:资源位置属性
伙计们,我在加载静态资源时也遇到问题。
我想我已经把一切都设置好了。但我不明白 mvc:resources 的 location 属性。它是做什么用的?
如果我的静态资源位于 VAADIN/themes/theme/... 位置(在多个子文件夹、图像、css、js 中),位置和映射属性的正确值应该是什么?
当我在配置中有以下内容时:
<mvc:resources location="/VAADIN/" mapping="/VAADIN/**"/>
它不起作用。我想日志的以下部分是相关的:
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 Status 404 例如 http://127.0.0.1/VAADIN/themes/theme/css/style.css
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 mvc:resources. What is it for?
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?
When I have following in configuration:
<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
I receive HTTP Status 404 for e.g. http://127.0.0.1/VAADIN/themes/theme/css/style.css
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
location
是放置资源的文件夹的位置。 XSD 文档写道:另一方面,
mapping
属性是:因此
mapping
指定在哪个 uri 下可以在 Web 上访问资源,而location
指定这些资源位于磁盘上的位置。location
is the location to the folder where the resources are placed. The XSD docs write:On the other hand, the
mapping
attribute is:So
mapping
specifies under what uri will resources be accessible on the web, whilelocation
specifies where are these resources located on the disk.我的猜测是您没有正确引用该位置。
WAR的顶级目录(其中
情况
location="/VAADIN/"
是正确)
情况一定是
位置=“类路径:/VAADIN/”
)?My Guess is that you're not referencing the location correctly.
WAR's top level directory (in which
case
location="/VAADIN/"
iscorrect)
case it must be
location="classpath:/VAADIN/"
) ?也许您已经配置了一些在resourcehttprequestresolver(或任何它的名称)之前启动的处理程序映射
检查您是否没有 AbstractUrlHandlerMapping 或任何其他处理程序映射来停止具有 order 属性的映射链。
或者使用以下顺序配置资源解析器:
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" />
设置一个处理程序来提供静态内容。映射属性
设置为 /resources/**,其中包含一个 Ant 风格的通配符来指示该路径
必须以 /resources 开头,但可以包含其任何子路径。位置属性
指示要提供的文件的位置。按照此处的配置,任何请求
以 /resources 开头的路径将自动从 /resources 提供服务
应用程序根目录下的文件夹。因此,我们所有的图像、样式表、
JavaScript 和其他静态内容需要保存在应用程序的 /resources 中
文件夹。
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.