gpt4 book ai didi

Spring MVC mvc :resources location attribute

转载 作者:行者123 更新时间:2023-12-01 11:06:23 25 4
gpt4 key购买 nike

伙计们,我也有加载静态资源的问题。

我认为我已正确设置所有内容。但是我不明白 mvc:resourceslocation 属性。它有什么用?

如果我的静态资源位于 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 状态 404,例如http://127.0.0.1/VAADIN/themes/theme/css/style.css

最佳答案

location 是放置资源的文件夹的位置。 XSD docs写:

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 属性是:

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

因此 mapping 指定在什么 uri 下可以在网络上访问资源,而 location 指定这些资源在磁盘上的位置。

关于 Spring MVC mvc :resources location attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com