title: How to get path in spring to access configuration file
body: <p>I have written a Spring program where the following classes, interfaces and xml files are in different packages. I use Eclipse Kepler.</p>
  
  <p><img src="https://i.stack.imgur.com/e9XB0.jpg" alt="file structure"></p>
  
  <h3>SelectClient.java</h3>
  
  <pre><code>package com.rajeev.spring.action;
  
  import org.springframework.beans.factory.xml.XmlBeanFactory;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  
  import com.rajeev.spring.DAOI.Select;
  
  /**
   * @author rajeev
   *
   * 
   */
  public class SelectClient {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          String path=System.getProperty("user.dir");
          System.out.println(path+"/src/com/rajeev/spring/DAOImpl/SelectCfg.xml");
          Resource resource=new ClassPathResource(path+"/src/com/rajeev/spring/DAOImpl/SelectCfg.xml");
          XmlBeanFactory beanFactory=new XmlBeanFactory(resource);
          Object object=beanFactory.getBean("sb");
          Select select=(Select)object;
          System.out.println("emp name is:"+select.fetchName(101));
      }
  
  }
  </code></pre>
  
  <p>The problem is that when I execute the <code>SelectClient.java</code>, it is giving following error</p>
  
  <pre>
  E:\javahyd\eclipse\Spring_DataSource_Object_Inject/src/com/rajeev/spring/DAOImpl/SelectCfg.xml
  Jan 17, 2014 11:41:43 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from class path resource [E:/javahyd/eclipse/Spring_DataSource_Object_Inject/src/com/rajeev/spring/DAOImpl/SelectCfg.xml]
  Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [E:/javahyd/eclipse/Spring_DataSource_Object_Inject/src/com/rajeev/spring/DAOImpl/SelectCfg.xml]; nested exception is java.io.FileNotFoundException: class path resource [E:/javahyd/eclipse/Spring_DataSource_Object_Inject/src/com/rajeev/spring/DAOImpl/SelectCfg.xml] cannot be opened because it does not exist
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
      at org.springframework.beans.factory.xml.XmlBeanFactory.(XmlBeanFactory.java:78)
      at org.springframework.beans.factory.xml.XmlBeanFactory.(XmlBeanFactory.java:66)
      at com.rajeev.spring.action.SelectClient.main(SelectClient.java:26)
  Caused by: java.io.FileNotFoundException: class path resource [E:/javahyd/eclipse/Spring_DataSource_Object_Inject/src/com/rajeev/spring/DAOImpl/SelectCfg.xml] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
      ... 4 more
  </pre>
  
  <p>The above exception, is due to the path. When I use the same path in run(windows+r) the particular file it is opening. I dont want to keep my configuration file out of any packages.</p>