简体   繁体   English

使用Spring ResourceServlet同时提供多个资源

[英]Using Spring ResourceServlet to serve multiple resources simultaneously

The JavaDoc for the ResourceServlet states that it can return a list of resources. ResourceServlet的JavaDoc声明它可以返回资源列表。 But examples of this usage pattern seem to be sparse at best. 但这种使用模式的例子似乎很少。

We have a web.xml with the following: 我们有一个带有以下内容的web.xml:

<servlet>
  <servlet-name>Resource</servlet-name>
  <servlet-class>org.springframework.web.servlet.ResourceServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>Resource</servlet-name>
  <url-pattern>/combo</url-pattern>
</servlet-mapping>

When we make a request to url along the lines of: http://localhost:8080/app/combo?resource=js/file1.js;js/file2.js 当我们按以下方式提出url请求: http:// localhost:8080 / app / combo?resource = js / file1.js; js / file2.js

We only seem to get file1 in the response. 我们似乎只在响应中获取了file1。

What would a proper configuration be for this use case? 这个用例的正确配置是什么?

The ResourceServlet has been deprecated in favour of using <mvc:resources /> However, it doesn't handle multiple resources. 不推荐使用ResourceServlet ,而是使用<mvc:resources />但是,它不处理多个资源。 You'd have to make your own controller to do that. 你必须让自己的控制器来做到这一点。

As for the ResourceServlet , the delimiters used in the code are ,; \\t\\n 至于ResourceServlet ,代码中使用的分隔符是,; \\t\\n ,; \\t\\n - any of them should work. ,; \\t\\n - 任何一个都应该有效。

The problem in our case turned out to be that the application used the mvc:resource utility to handle versioning of the static files. 我们的案例中的问题是应用程序使用mvc:resource实用程序来处理静态文件的版本控制。 The backend of the mvc:resource utility will not respond to multiple files properly as Bosho noted, and I was aware of too from looking at the source. mvc:resource实用程序的后端不会像Bosho所说的那样正确响应多个文件,而且我也从通知来源看到了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM