Skip to content

getServletContext().getResourceAsStream() returns null #12868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gardellajuanpablo opened this issue Apr 16, 2018 · 3 comments
Closed

getServletContext().getResourceAsStream() returns null #12868

gardellajuanpablo opened this issue Apr 16, 2018 · 3 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@gardellajuanpablo
Copy link

gardellajuanpablo commented Apr 16, 2018

Hello team,

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 make a reproducible project at
reproissue.zip

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.

I saw similar issues filed before and marked solved, but maybe in spring boot 2.0.1 is failing again. Similar issues: #8525

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 16, 2018
@snicoll snicoll changed the title BUG: getServletContext().getResourceAsStream() returns null getServletContext().getResourceAsStream() returns null Apr 16, 2018
@wilkinsona
Copy link
Member

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. If you require further guidance, please ask a question on Stack Overflow.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 23, 2018
@gardellajuanpablo
Copy link
Author

Yes thanks I finally solved using "classpath:/static" and by using classloader instead servlet context to find the file.

@gardellajuanpablo
Copy link
Author

Already answered in Stack Overflow, I've copied your answer there: https://stackoverflow.com/questions/49883410/getservletcontext-getresourceasstream-returns-null/49980484#49980484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants