title: Cannot find class for bean with name defined in class path resource [applicationContext.xml]
body: <p>I'm posting my query after visiting numerous question posted before on same context, unfortunately none of them resolved my problem. I'm trying a complete xml based configuration in spring without using any annotation. But as soon as i launch the application, i'm getting the following exception.</p>
  
  <blockquote>
    <p>Cannot find class [com.kashyap.springboot.xml.JdbcConnectionXML.java]
    for bean with name 'connection' defined in class path resource
    [applicationContext.xml]; nested exception is
    java.lang.ClassNotFoundException:
    com.kashyap.springboot.xml.JdbcConnectionXML.java</p>
  </blockquote>
  
  <p>Things i've already taken care of :-</p>
  
  <ol>
  <li>Namespace for component scan re-examined.</li>
  <li>Tag for component scan entered.</li>
  <li>Bean tag with proper classes' qualified name re-examined.</li>
  <li>Bean property and references re-visited.</li>
  <li>applicationContext.xml is located on path src/main/resources so no
  absolute path required.</li>
  <li>Context initialized with ClassPathXmlApplicationContext class.</li>
  </ol>
  
  <p>Classes are already defined with default public constructors for instantiation required by reflection.(though it is not mandatory, used it as precaution). Alas!!! none of the these things worked. Please find the classes and xml below.</p>
  
  <pre><code>package com.kashyap.springboot.xml;
  public class JdbcConnectionXML {
      public JdbcConnectionXML(){
          System.out.println("JDBC XML Constructor Called");
      }
  }
  
  package com.kashyap.springboot.xml;
  public class PrototypeXMLDAO {
      public PrototypeXMLDAO(){
          System.out.println("PrototypeXMLDAO Constructor Called");
      }   
      private JdbcConnectionXML connection;
      public JdbcConnectionXML getConnection() {
          return connection;
      }
      public void setConnection(JdbcConnectionXML connection) {
          this.connection = connection;
      }
  }
  
  
  package com.kashyap.springboot.xml;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  public class SpringbootdevApplication {
      public static void main(String[] args) {
          try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");) {
              PrototypeXMLDAO pdCDIOne = context.getBean(PrototypeXMLDAO.class);
              PrototypeXMLDAO pdCDITwo = context.getBean(PrototypeXMLDAO.class);
              System.out.println(pdCDIOne);
              System.out.println(pdCDIOne.getConnection());
              System.out.println(pdCDITwo);
              System.out.println(pdCDITwo.getConnection());
          }
      }
  }
  
  &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" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;context:component-scan base-package="com.kashyap.springboot.xml" /&gt;
  
      &lt;bean id="connection" class="com.kashyap.springboot.xml.JdbcConnectionXML"&gt;
      &lt;/bean&gt;
      &lt;bean id="prototype" class="com.kashyap.springboot.xml.PrototypeXMLDAO"&gt;
          &lt;property name="connection" ref="connection"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>The stack-trace on console as follows:-</p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.springframework.beans.factory.CannotLoadBeanClassException: Cannot
    find class [com.kashyap.springboot.xml.JdbcConnectionXML.java] for
    bean with name 'connection' defined in class path resource
    [applicationContext.xml]; nested exception is
    java.lang.ClassNotFoundException:
    com.kashyap.springboot.xml.JdbcConnectionXML.java     at
    org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1380)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:670)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007)
      at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:739)
      at
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
      at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
      at
    org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144)
      at
    org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85)
      at
    com.kashyap.springboot.xml.SpringbootdevApplication.main(SpringbootdevApplication.java:13)
    Caused by: java.lang.ClassNotFoundException:
    com.kashyap.springboot.xml.JdbcConnectionXML.java     at
    java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:357)     at
    org.springframework.util.ClassUtils.forName(ClassUtils.java:255)  at
    org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:418)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1428)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1372)
      ... 10 more</p>
  </blockquote>
  
  <p>If required i'll post the pom.xml too. Any sort of help will be highly appreciated.</p>