title: How to pass local filename to ClassPathXmlApplicationContext?
body: <p>By "local filename" I mean that resource file is located in the same directory as class file. In the case below this is <code>JUnitRunner.class</code> file. Java's <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource%28java.lang.String%29" rel="nofollow"><code>getResource()</code></a> file can handle this if path does not start with <code>/</code>'</p>
  
  <p>I can't figure out, how to do the same <code>ClassPathXmlApplicationContext</code> constructor? </p>
  
  <pre><code>
  package springtests;
  
  import java.io.File;
  import java.net.URISyntaxException;
  import java.net.URL;
  
  import org.junit.Test;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class JUnitRunner {
  
      private final static Logger log = LoggerFactory.getLogger(JUnitRunner.class);
  
      @Test
      public void test() throws URISyntaxException {
  
          String filename = "test01.xml";
  
          URL url = getClass().getResource(filename);
  
  
          File file = new File(url.toURI());
          log.info("File exists: {}", file.exists());
  
          try {
              new ClassPathXmlApplicationContext(filename);
          }
          catch(Exception e) {
              log.error("Can't load context", e);
          }
  
      }
  }
  </code></pre>
  
  <p>the output follows</p>
  
  <pre>
  15:32:27,375 3    [main] INFO  springtests.JUnitRunner  - File exists: true
  15:32:27,422 50   [main] INFO  org.springframework.context.support.ClassPathXmlApplicationContext  - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ee3aa7: startup date [Thu Nov 01 15:32:27 MSK 2012]; root of context hierarchy
  15:32:27,475 103  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [test01.xml]
  15:32:27,477 105  [main] ERROR springtests.JUnitRunner  - Can't load context
  org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [test01.xml]; nested exception is java.io.FileNotFoundException: class path resource [test01.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)
  
  ...
  </pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>XML file is located in the same folder as class file. It is visible from the fact that <code>getResource()</code> see it.</p>