Results 1 to 3 of 3

Thread: Retrieving a file from WEB-INF without a servlet context

  1. #1
    Join Date
    Jul 2008
    Posts
    18

    Default 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.

    ie,
    in my app-context.xml

    Code:
    <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?

    thanks

  2. #2
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    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.
    http://www.jroller.com/thebugslayer - notes on java, scala and other development stuff.

  3. #3
    Join Date
    Jul 2008
    Posts
    18

    Default

    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

Posting Permissions

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