Results 1 to 2 of 2

Thread: ResourceLoader Not Finding Resources During Integration Tests

  1. #1
    Join Date
    Nov 2005
    Location
    Wayne, PA
    Posts
    4

    Question 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.
    Code:
    //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.

    Code:
    //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.

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

  2. #2
    Join Date
    Nov 2005
    Location
    Wayne, PA
    Posts
    4

    Default

    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?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •