Announcement Announcement Module
Collapse
No announcement yet.
Problem in get web app root directory in normal class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      thank you very much!

      it works!

      Comment

      Working...
      X