Announcement Announcement Module
No announcement yet.
Retrieving a file from WEB-INF without a servlet context Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving a file from WEB-INF without a servlet context

    Is there a way to do this without the ServletContext?

    Normally, if I had the servlet context, i would do a ServletContext.getResourceasStream() etc, but I'm using Spring2.5, and I have a class that I would like to have initialized automatically, but can't figure out a way to pass in the ServletContext.

    in my app-context.xml

    <bean id="test" class="testClass" init-method="init"/>
    I need a file in WEB-INF to initialize some data in the class.

    I've tried doing a

    InputStream in = new FileInputStream( "/WEB-INF/my.xml" );

    but from my class, i get a null pointer. Any ideas?


  • #2
    Hi jjunos,

    There recommended way is to use servletContext. In Spring you can easily get this by implementing org.springframework.web.context.ServletContextAwar e interface with your bean class, and you will have a call back method with it's servletContext object as parameter.


    • #3
      Yeah, that was the way I went. It actually ended up being somewhat overkill, I ended up in the end refactoring the class and passing/retrieving the file via a Resource that was injected in. Worked like a charm