java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist

Spring JIRA | Michael Osipov | 2 years ago
  1. 0

    Say I have this mapping: {code} <mvc:resources mapping="/docs/**" location="classpath:/docs/" /> {code} Request {{docs/}} or any other subdirectory ends up in a HTTP 500: {noformat} 19:27:23.669 [http-8081-2] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:407) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:241) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.41] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [catalina.jar:6.0.41] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.41] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.41] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina.jar:6.0.41] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) [tomcat-coyote.jar:6.0.41] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) [tomcat-coyote.jar:6.0.41] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.41] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67] {noformat} I would rather expect here 200 or better yet 204. The directory does exist but WebMVC does not know how to handle. I have debugged the implementation and {{Resource}} is retrieved but {{getInputStream}} fails. Moreover, content length is 0. I don't expect an extensive handling like in Apache`s {{mod_dir}} but at least not a 500. Meanwhile, I have applied this workaround: {code} <urlrewrite> <rule> <name>mod_dir fake</name> <from>^/docs(/rest)?$</from> <to type="permanent-redirect" last="true">%{context-path}/docs$1/</to> </rule> <rule> <name>mod_dir fake</name> <from>^/docs(.+)/$</from> <to last="true">/docs$1/index.html</to> </rule> </urlrewrite> {code}

    Spring JIRA | 2 years ago | Michael Osipov
    java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist
  2. 0

    Say I have this mapping: {code} <mvc:resources mapping="/docs/**" location="classpath:/docs/" /> {code} Request {{docs/}} or any other subdirectory ends up in a HTTP 500: {noformat} 19:27:23.669 [http-8081-2] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:407) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:241) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.41] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [catalina.jar:6.0.41] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.41] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.41] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina.jar:6.0.41] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) [tomcat-coyote.jar:6.0.41] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) [tomcat-coyote.jar:6.0.41] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.41] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67] {noformat} I would rather expect here 200 or better yet 204. The directory does exist but WebMVC does not know how to handle. I have debugged the implementation and {{Resource}} is retrieved but {{getInputStream}} fails. Moreover, content length is 0. I don't expect an extensive handling like in Apache`s {{mod_dir}} but at least not a 500. Meanwhile, I have applied this workaround: {code} <urlrewrite> <rule> <name>mod_dir fake</name> <from>^/docs(/rest)?$</from> <to type="permanent-redirect" last="true">%{context-path}/docs$1/</to> </rule> <rule> <name>mod_dir fake</name> <from>^/docs(.+)/$</from> <to last="true">/docs$1/index.html</to> </rule> </urlrewrite> {code}

    Spring JIRA | 2 years ago | Michael Osipov
    java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist
  3. 0

    Could not find spring-postinitialize.xsd when container starts

    GitHub | 2 years ago | ricoyu
    java.io.FileNotFoundException: class path resource [fr/zebasto/spring/post/initialize/config/spring-postinitialize.xsd] cannot be opened because it does not exist
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Upgrading to 1.1.2 breaks Classloading on Windows

    GitHub | 2 years ago | arafalov
    java.io.FileNotFoundException: class path resource [banner.txt] cannot be opened because it does not exist

  1. stigkj 1 times, last 3 weeks ago
  2. kjhdofjosvs 1 times, last 1 month ago
  3. marcbouvierdav 1 times, last 2 months ago
  4. linxiaolong 2 times, last 3 months ago
  5. ruifung 2 times, last 3 months ago
18 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.io.FileNotFoundException

    class path resource [docs/rest] cannot be opened because it does not exist

    at org.springframework.core.io.ClassPathResource.getInputStream()
  2. Spring Core
    ClassPathResource.getInputStream
    1. org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    1 frame
  3. Spring MVC
    FrameworkServlet.doGet
    1. org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:407)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    2. org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:241)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    3. org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    4. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    5. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    6. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    7. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    7 frames
  4. JavaServlet
    HttpServlet.service
    1. javax.servlet.http.HttpServlet.service(HttpServlet.java:617)[servlet-api.jar:na]
    1 frame
  5. Spring MVC
    FrameworkServlet.service
    1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    1 frame
  6. JavaServlet
    HttpServlet.service
    1. javax.servlet.http.HttpServlet.service(HttpServlet.java:723)[servlet-api.jar:na]
    1 frame
  7. Glassfish Core
    CoyoteAdapter.service
    1. org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)[catalina.jar:6.0.41]
    2. org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)[catalina.jar:6.0.41]
    3. org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)[catalina.jar:6.0.41]
    4. org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)[catalina.jar:6.0.41]
    5. org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)[catalina.jar:6.0.41]
    6. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)[catalina.jar:6.0.41]
    7. org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)[catalina.jar:6.0.41]
    8. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)[catalina.jar:6.0.41]
    9. org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)[catalina.jar:6.0.41]
    10. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)[catalina.jar:6.0.41]
    10 frames
  8. Grizzly HTTP
    JIoEndpoint$Worker.run
    1. org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)[tomcat-coyote.jar:6.0.41]
    2. org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)[tomcat-coyote.jar:6.0.41]
    3. org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)[tomcat-coyote.jar:6.0.41]
    3 frames
  9. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:745)[na:1.7.0_67]
    1 frame