Reputation: 382
I'm using spring boot 2.0.1.RELEASE.
I'm migrating an application from spring (a WAR) to spring-boot. It uses GWT which uses a servlet that depends on getServletContext().getResourseAsStream()
method works as expected.
I've uploaded a reproducible project at https://github.com/spring-projects/spring-boot/issues/12868.
When doing a GET Request to http://localhost:8080/mymodule/afile.rpc you can see the file is returned, but if you execute http://localhost:8080/mymodule/dispatch a servlet is executed, the servlet uses getServletContext().getResourseAsStream()
to return the same file, but null is returned in that case.
Any idea?
I saw similar issues filed before and marked solved, but maybe in spring boot 2.0.1 is failing again. Similar issues: #8525
Upvotes: 0
Views: 1784
Reputation: 382
According Andy Wilkinson
Serving static resources from the classpath:static is a Spring MVC feature that is auto-configured by Spring Boot. The servlet container and servlet context know nothing about it is to be expected that the attempt to access the file via the servlet context does not work.
If you want static content to be served by the servlet container, you should place it in a location where the servlet container can find it. For example, in the root of an application packaged as a war file
I've finally adjusted the servlet to use the classloader instead the servlet context to pick the file.
Upvotes: 2