简体   繁体   中英

Using Spring ResourceServlet to serve multiple resources simultaneously

The JavaDoc for the ResourceServlet states that it can return a list of resources. But examples of this usage pattern seem to be sparse at best.

We have a web.xml with the following:

<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

We only seem to get file1 in the response.

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. You'd have to make your own controller to do that.

As for the ResourceServlet , the delimiters used in the code are ,; \\t\\n ,; \\t\\n - any of them should work.

The problem in our case turned out to be that the application used the mvc:resource utility to handle versioning of the static files. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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