title: Spring/Java org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [C:\launchCodeFiles\src\main\java\RunMario.java]
body: <p>I am learning Java and told to learn Spring.  I am writing a simple program and get this error message (I am using IntelliJ Idea IDE):</p>
  
  <pre><code>first line of main
  2015-05-06 11:37:38 INFO  ClassPathXmlApplicationContext:510 -   Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1e717c2: startup date [Wed May 06 11:37:38 CDT 2015]; root of context hierarchy
  2015-05-06 11:37:38 INFO  XmlBeanDefinitionReader:317 - Loading XML bean definitions from class path resource [ApplicationContext.xml]
  2015-05-06 11:37:39 WARN  ClassPathXmlApplicationContext:487 - Exception encountered during context initialization - cancelling refresh attempt
  Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [C:\launchCodeFiles\src\main\java\RunMario.java] for bean with name 'obstacle1' defined in class path resource [ApplicationContext.xml]; nested exception is java.lang.ClassNotFoundException: C:\launchCodeFiles\src\main\java\RunMario.java
  org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [C:\launchCodeFiles\src\main\java\RunMario.java] for bean with name 'obstacle1' defined in class path resource [ApplicationContext.xml]; nested exception is java.lang.ClassNotFoundException: C:\launchCodeFiles\src\main\java\RunMario.java
  at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
  at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
  at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
  at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
  at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
  at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
  at RunMario.main(RunMario.java:17)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at RunMario.main(RunMario.java:17)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  Caused by: java.lang.ClassNotFoundException: C:\launchCodeFiles\src\main\java\RunMario.java
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  Caused by: java.lang.ClassNotFoundException: C:\launchCodeFiles\src\main\java\RunMario.java
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
  at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
  ... 15 more
  at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
  at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
  ... 15 more
  
  Process finished with exit code 1
  </code></pre>
  
  <p>My ApplicationContext.xml file is as follows.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
      &lt;bean id="obstacle1" class="C:\launchCodeFiles\src\main\java\RunMario.java"&gt;
      &lt;constructor-arg name= "marioObstacles" ref="obstacle"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="obstacle" class="C:\launchCodeFiles\src\main\java\MarioObstacles.java"&gt;
      &lt;constructor-arg name="obstacle" value="0"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I copied and pasted the RunMario class file path from the project panel so it should be the fully qualified path.  Here is the RunMario.java file:</p>
  
  <pre><code>import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  import java.util.Scanner;
  
  public class RunMario {
  
      private MarioObstacles marioObstacles;
  
      public RunMario(MarioObstacles marioObstacles) {
      this.marioObstacles = marioObstacles;
      }
      public static void main(String[] arguments) {
     //        RunMario runMario1 = new    RunMario(MarioObstacles.getInstance());
          System.out.println("first line of main");
  
          ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
          System.out.println("just out of context");
  
          RunMario obj = (RunMario) context.getBean("obstacle1");
          obj.start();
      }
  
      public void start() {
          System.out.println("first line of start");
          BuildOstacles pyramid = marioObstacles.pyramid();
          pyramid.setHeight(runMario());
          pyramid.buildPyramid();
          System.out.println(pyramid);
          System.out.println("exiting start");
      }
  
      public static int runMario() {
          System.out.println("entering runMario");
          int height;
          do {
              Scanner scan = new Scanner(System.in);
              System.out.println("Please enter a whole number between 1 and 10");
              height = scan.nextInt();
          } while (height &lt; 1 || height &gt; 10);
          return height;
      }
  }
  </code></pre>
  
  <p>I have spent 2 days searching for the answer.  I cannot seem to figure it out.</p>
  
  <p>Any suggestions?</p>