-
Notifications
You must be signed in to change notification settings - Fork 41.2k
ServletContext getResourceAsStream for file in META-INF/resources does not work in an IDE, spring-boot:run, or bootRun #8525
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
Comments
It may be this change that was made in 1.4.5 and 1.5.2. When you say this it works fine when running from the command line, how are you running your application? Are you using |
java -jar |
And interestingly mvn spring-boot:run causes the error as well. |
Hi, attached another sample project that seems too reproduce this same issue, this time when trying to set up SiteMesh 2. With 1.5.1, the file from
The line causing the issue involves one (this happens when running app from console, no STS involved) |
oh, and notice that we need |
@davidmelia Thanks for the sample project and the details on how you're running the app. As I suspected, the problem was introduced by the changes for #8299. Here's a work around: @Bean
public TomcatEmbeddedServletContainerFactory tomcat() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.addContextCustomizers((context) -> {
context.addLifecycleListener((event) -> {
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
ClassLoader classLoader = getClass().getClassLoader();
if (classLoader instanceof URLClassLoader) {
for (URL url: ((URLClassLoader)classLoader).getURLs()) {
if ("file".equals(url.getProtocol())) {
File file = new File(url.getFile());
if (file.isFile() || new File(file, "META-INF/resources").isDirectory()) {
context.getResources().createWebResourceSet(ResourceSetType.RESOURCE_JAR, "/", url, "/META-INF/resources");
}
}
}
}
}
});
});
return tomcatEmbeddedServletContainerFactory;
} |
@juanpablo-santos Your sample project fails for me with both 1.5.1 and 1.5.2. That's actually what I would expect as, per the servlet spec, loading content from |
a2cf045 should have referenced this issue. |
Hi @wilkinsona, thanks for looking into the sample. In it, with 1.5.2, http://localhost:8080/index.html gets you the "Whitelabel Error Page", with the underlying exception being:
This is caused because With 1.5.1, the same URL gets another "Whitelabel Error Page", but this time the underlying exception is:
which is expected as Sitemesh decorator itself is a blank page, there aren't any controllers, etc. But the former line is able to locate the decorators file inside In any case, applying the provided workaround with 1.5.2 also fixes the issue, so thanks for your prompt response! :-) |
Hi, found one corner case with the above solution, spring-boot maven plugin won't start if the project has a dependency of type pom, yielding the following exception:
one possible quick fix is to substitue the innermost
|
@juanpablo-santos Thank you for trying the snapshot |
I've just realised the failure above wasn't with the fix in the snapshots, it's with the workaround I suggested above. The fix in the snapshots is more defensive. |
Update spring boot to fix spring-projects/spring-boot#8525
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I've just upgraded from Boot 1.5.1 to 1.5.2 and am now getting
null
back fromgetServletContext().getResourceAsStream
. This happens in STS (3.8.3) only and not when running from the command line.I've distilled the problem down into a simple project on Bit Bucket
My simple project consists of a WAR which contains a Servlet 'SomeServlet' which looks for a resource
/scripts/lib/dave.js
inside a dependent JAR/resources/META-INF/resources
. If the resource is not found I throw an exception.. Boot 1.5.1 works fine on both command line and in STS. Boot 1.5.2 works fine on the command line but breaks in Eclipse returning
null
.Any ideas?
Thanks
The text was updated successfully, but these errors were encountered: