title: Exception no such bean definition
body: <pre><code>Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'testDao' is defined
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
  at com.test.main.java.TestMain.main(TestMain.java:30)
  </code></pre>
  
  <p>this is my main class which is calling bean testDao .</p>
  
  <pre><code>public class TestMain {
  
      /**
       * @param args
       * @throws SQLException
       * @throws ClassNotFoundException
       */
      public static void main(String[] args) throws SQLException,
              ClassNotFoundException, FileNotFoundException, NullPointerException {
  
          ApplicationContext ctx = new ClassPathXmlApplicationContext(
                  "springNew.xml");
          TestDao dao = ctx.getBean("testDao", TestDao.class);
  
          Test test = dao.getTest(1);
          System.out.println(test.getName());
      }
  }
  </code></pre>
  
  <p>"THIS is >>>testDao file"</p>
  
  <pre><code>package com.test.dao.java;
  
  import java.io.FileNotFoundException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  import org.springframework.stereotype.Component;
  import org.springframework.stereotype.Repository;
  
  import com.test.java.Test;
  
  @Component
  public class TestDao {
      static PreparedStatement ps;
      ResultSet rs;
      Connection conn = null;
  
      private Connection getConnection() throws SQLException,
              ClassNotFoundException, FileNotFoundException, NullPointerException {
  
          if (conn == null) {
              try {
                  Class.forName("org.postgresql.Driver");
                  conn = DriverManager.getConnection(
                          "jdbc:postgresql://localhost:5432/testdb", "postgres",
                          "postgres");
                  conn.close();
              } catch (Exception e) {
                  e.printStackTrace();
  
              }
          }
          return conn;
  
      }
  
      /**
       * @param testId
       * @return
       * @throws SQLException
       * @throws ClassNotFoundException
       * @throws NullPointerException
       * @throws FileNotFoundException
       */
      public Test getTest(int testId) throws SQLException,
              ClassNotFoundException, FileNotFoundException, NullPointerException {
  
          conn = getConnection();
          try {
  
              conn = getConnection();
              ps = conn
                      .prepareStatement("SELECT * FROM testdb.testtab where id =?");
              ps.setInt(1, testId);
              Test test = null;
              rs = ps.executeQuery();
              if (rs.next()) {
                  test = new Test(testId, rs.getString("name"));
              }
  
              return test;
          } finally {
              rs.close();
              ps.close();
              conn.close();
          }
      }
  }
  </code></pre>
  
  <p>AND this is >>>>springNew.xml</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.xsd 
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd "
         xmlns:context="http://www.springframework.org/schema/context"&gt;
  
         &lt;!-- &lt;context-annotation-config/&gt; --&gt;
         &lt;context:component-scan base-package="com.test.main"/&gt;
  &lt;/beans&gt;
  </code></pre>