Announcement Announcement Module
No announcement yet.
ResourceLoader Not Finding Resources During Integration Tests Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ResourceLoader Not Finding Resources During Integration Tests

    I am having trouble understanding how the ResourceLoader locates resources. When I deploy the code on the server it runs fine but it fails in my eclipse test environment when running integration tests. My project is laid out as a typical maven webapp with separate src and test code trees.
    //This works fine when deployed but fails during tests
    Resource file = resourceLoader.getResource("/WEB-INF/reports/report1.jasper");
    I can make the tests work if I hard code the resource location with the full path but it destroys portability.

    //HARD CODED: This works fine in tests but fails in deployed
    Resource file = resourceLoader.getResource("file:/eclipse_work/myApp/src/main/webapp/WEB-INF/reports/report1.jasper");
    I tried the following (and a few other variations) after reading the reference a little more closely but it doesn't seem to work either.

    Resource file = resourceLoader.getResource("classpath*:WEB-INF/reports/report1.jasper");
    Any idea what I might be missing?

  • #2
    after a bit more research it looks like the resourceloader is using a GenericApplicationContext when running the integration test that fails. The ResourceLoader works fine when running under Tomcat because it uses WebApplicationContext.

    Is there a consistent way to reference a file in the WEB-INF folder of a project using a ResourceLoader no matter whether you are using GenericApplicationContext or WebApplicationContext?