Results 1 to 3 of 3

Thread: Problem in get web app root directory in normal class

  1. #1
    Join Date
    Oct 2004
    Posts
    4

    Default Problem in get web app root directory in normal class

    hi, i want to get config file in /WEB-INF/myconfig.xml in a class but not a Servlet like this:
    Code:
    public class ConfigLoader {
        private String configFile;
        public ConfigLoader() {
            // how can i get the /WEB-INF/myconfig.xml file here?
        }
    anybody can help me how to get the real directory of /WEB-INF/ in this normal class without ServletContext or any HttpServletRequest?

    thank you!

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Without any references to the SErvletContext or HttpServletRequest, you won't be able to retrieve something from /WEB-INF/...

    With Spring Dependency Injection however you can rely on Spring's resource infrastructure. If your bean is managed by Spring and located in a WebApplicationContext you could for example do teh following:

    Code:
    public class ConfigLoader {
      private Resource configFile;
      public void setConfigFile(Resource res) {
        this.configFile = res;
      }
    }
    together with:

    Code:
    <bean id="configLoader" class="ConfigLoader">
      <property name="configFile"><value>/WEB-INF/myconfig.xml</value></property>
    </bean>
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Oct 2004
    Posts
    4

    Default

    thank you very much!

    it works!

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  4. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  5. Replies: 3
    Last Post: Aug 30th, 2004, 09:56 AM

Posting Permissions

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