Closed
Description
The behavior of javax.servlet.ServletContext#getResourcePaths
and (its sibling methods) is inconstent, depending on how the application is packaged and which servlet container is used.
I've created the following example application to demonstrate the problem: https://github.com/larsgrefer/servlet-context-test
All example applications in this repository return a list of all found resources under localhost:8080/resources
Jar based applications
Expected behaviour
All applications should always return the following items (in any order)
/library-classpath-resource.txt
/classpath-resource.txt
Actual behaviour:
Servlet Container | gradle bootRun |
java -jar |
docker container build with jib |
---|---|---|---|
Tomcat | Shows both items, but also a third one(*) | /classpath-resource.txt is missing |
both items are shown |
Undertow | Both items are missing | Both items are missing | Both items are missing |
Jetty | Shows both items, but also a third one(*) | /classpath-resource.txt is missing |
both items are shown |
War based applications
Expected behaviour
All applications should always return the following items (in any order)
/library-classpath-resource.txt
/war-resource.txt
Actual behaviour:
Servlet Container | gradle bootRun |
java -jar |
docker container build with jib (**) |
---|---|---|---|
Tomcat | /classpath-resource.txt is shown in addition to the expected ones |
All items are shown as expected | All items are shown as expected |
Undertow | Only /war-resource.txt is shown |
All items are missing | All items are shown as expected |
Jetty | /classpath-resource.txt is shown in addition to the expected ones |
All items are shown as expected | All items are shown as expected |
(**) jib uses a distroless jetty for war based project, so this is a traditional deployment to an external servlet container from the spring-boot point of view
Conclusion
- (*)
src/main/webapp
seems to be used as resource root, even if the project is not war-based. classpath*:META-INF/resources
is only used as resource root by Tomcat and Jetty, but not by undertow.classpath*:META-INF/resources
is not used as resource root when its theBOOT-INF/classes
orWEB-INF/classes
folder of a repacked jar or war.
Metadata
Metadata
Assignees
Labels
No labels