Announcement Announcement Module
Collapse
No announcement yet.
read a resource file in WEB-INF Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • read a resource file in WEB-INF

    I have an xml file in my web app (WEB-INF/myresources.xml).
    I want to read it with spring, without passing from the application context (because I want to test my application with JUnit also).

    The solution I am using now is to hard-code the path (c:/..../myresources.xml) in my applicationContext.xml.

    But this is not a good solution because I have to re-configure the file if I change the path of my application.

    Thanks.

  • #2
    If you put the file under WEB-INF/classes then you can classload it (i.e. this.getClass().getResourceAsStream('/myresources.xml') - just make sure that it's in the classpath for your unit tests and it should work fine.

    Or, load it from the servletContext (using getServletContext().getResourceAsStream('/WEB-INF/myresources.xml')) in the web app before passing the stream to the object that needs it; in your unit test you can create the stream however you like.

    Comment

    Working...
    X