title: context.xml file not found
body: <p>In Spring framework for Java, I create my beans using context.xml file and then load it with <code>ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");</code>.</p>
  
  <p>My program throws an exception <code>java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist</code>. </p>
  
  <p>The file exists. I use Gradle for dependencies management and my src folder (where the file is) is marked as resource in Intellij. I understand that for some reason even though my src folder should be included in classpath variable, gradle run task just can't grab it from here.</p>
  
  <p>When I use <code>new FileSystemXmlApplicationContext("context.xml");</code> instead everything works just fine, but I do need to use "Classpath" for my assignment.</p>
  
  <p>English is not my native language.</p>
  
  <p>This is my "Main" class:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
          ApplicationContext context = new FileSystemXmlApplicationContext("context.xml");
      }
  }
  </code></pre>
  
  <p>This is my beans from context.xml file</p>
  
  <pre><code>&lt;bean id="t1000" class="by.zti.main.impl.T1000"&gt;
      &lt;constructor-arg ref="sonyHead"/&gt;
      &lt;constructor-arg ref="toshibaLeg"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sonyHead" class="by.zti.main.impl.SonyHead"/&gt;
  &lt;bean id="sonyLeg" class="by.zti.main.impl.SonyLeg"/&gt;
  &lt;bean id="toshibaHead" class="by.zti.main.impl.ToshibaHead"/&gt;
  &lt;bean id="toshibaLeg" class="by.zti.main.impl.ToshibaLeg"/&gt;
  </code></pre>
  
  <p>This is my build.gradle file</p>
  
  <pre><code>group 'zti.spring.test'
  version '1.0-SNAPSHOT'
  
  apply plugin: 'java'
  apply plugin: 'application'
  apply plugin: 'idea'
  
  sourceCompatibility = 1.8
  targetCompatibility = 1.8
  
  mainClassName = 'by.zti.main.Main'
  
  repositories {
      mavenCentral()
  }
  
  jar {
      baseName = 'gs-gradle'
      version = '0.1.0'
  }
  
  dependencies {
      compile 'org.springframework:spring-context:4.3.6.RELEASE'
      compile fileTree(dir:'src', includes:  ['/*.xml,/*.properties'])
  }
  </code></pre>
  
  <p>Exception text</p>
  
  <pre>
      Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [context.xml]; nested exception is java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
      at by.zti.main.Main.main(Main.java:12)
  Caused by: java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
      ... 13 more
  </pre>
  
  <p>This is my file tree from my project</p>
  
  <p><a href="https://i.stack.imgur.com/y0tzQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y0tzQ.png" alt="enter image description here"></a></p>
  
  <p>Content of my classpath</p>
  
  <pre><code>/C:/Users/Cvazer/IdeaProjects/spring-test/build/classes/main/
  /C:/Users/Cvazer/IdeaProjects/spring-test/build/resources/main
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/4.3.6.RELEASE/5f3041020113e3202a7ae9defe36e7b5d2fb87eb/spring-context-4.3.6.RELEASE.jar
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/4.3.6.RELEASE/d70b2393d380cd468d9a14969efaf9022c67c0/spring-aop-4.3.6.RELEASE.jar
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/4.3.6.RELEASE/1585715ed598b76a23dac931c27aa039b189eafb/spring-beans-4.3.6.RELEASE.jar
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/4.3.6.RELEASE/690da099c3c2d2536210f0fd06ff3f336de43ad9/spring-core-4.3.6.RELEASE.jar
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/4.3.6.RELEASE/13b53568cfd7b308e70efcbac6cdd0c5d597ba1/spring-expression-4.3.6.RELEASE.jar
  /C:/Users/Cvazer/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar
  </code></pre>