title: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'BookDao' is defined
body: <p>I'm using spring 4 and hibernate. Can anybody help me! I'm using just annotation without an applicationcontext.xml I searched in the previous answers but it didn't' help me this error occurs:</p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'BookDao' is defined can anybody help me to found the error  
  INFO : org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@73a8dfcc: startup date [Thu Nov 19 20:28:23 WAT 2015]; root of context hierarchy
  INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  WARN : org.hibernate.mapping.RootClass - HHH000038: Composite-id class does not override equals(): project.model.OrderDetails
  WARN : org.hibernate.mapping.RootClass - HHH000039: Composite-id class does not override hashCode(): project.model.OrderDetails
  Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'BookDao' is defined
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1174)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
  </code></pre>
  
  <p>My classes are</p>
  
  <pre><code>    @Configuration
      @ComponentScan(basePackages ="project.genericdao ,")
      @EnableTransactionManagement
      public class AppConfig {
  
          @Bean(name = "dataSource")
          public DataSource getDataSource() {
              DriverManagerDataSource dataSource = new DriverManagerDataSource();
              dataSource.setDriverClassName("org.postgresql.Driver");
              dataSource.setUrl("jdbc:postgresql://localhost:5432/jeBouquine");
              dataSource.setUsername("postgres");
              dataSource.setPassword("basketball2009");
  
              return dataSource;
          }
          @Autowired
          @Bean(name = "sessionFactory")
          public SessionFactory getSessionFactory(DataSource dataSource) {
  
              LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
              sessionBuilder.scanPackages("project.model");
              sessionBuilder.addProperties(getHibernateProperties());
              return sessionBuilder.buildSessionFactory();
          }
  
          private Properties getHibernateProperties() {
              Properties properties = new Properties();
              properties.put("hibernate.show_sql", "true");
              properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
              return properties;
          }
          @Autowired
          @Bean(name = "transactionManager")
          public HibernateTransactionManager getTransactionManager(
                  SessionFactory sessionFactory) {
              HibernateTransactionManager transactionManager = new HibernateTransactionManager(
                      sessionFactory);
  
              return transactionManager;
          }
      }
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Service;
  
      import project.model.Book;
      import project.repository.RepositoryBookInterface;
      @Service("bookService")
      public class bookService implements IBookService{
          @Autowired
      private     RepositoryBookInterface bookDao ;
  
          public void add(Book obj) {
              bookDao.add(obj);
  
          }
  
  
      }
  
      public class GenericDaoImpl&lt;T&gt; implements GenericDao&lt;T&gt;{
  
          private Class&lt;T&gt; type;
  
          //@Resource(name = "sessionFactory")
          @Autowired
          private SessionFactory sessionFactory;
          public void setSessionFactory(SessionFactory sessionFactory) {
              this.sessionFactory = sessionFactory;
          }
          protected SessionFactory getSessionFactory() {
              if (sessionFactory == null)
                  throw new IllegalStateException("SessionFactory has not been set on DAO before usage");
              return sessionFactory;
          }
  
  
          public void save(T obj) {
              getSessionFactory().getCurrentSession().save(obj);
              getSessionFactory().getCurrentSession().flush();
  
          }
  
  
  
      @Repository("BookDao")
      public class RepositoryBook implements RepositoryBookInterface{
  
          private GenericDaoImpl&lt;Book&gt; dao;
  
          public RepositoryBook() {
              dao = new GenericDaoImpl&lt;Book&gt;(Book.class);
          }
  
          public void add(Book obj) {
              dao.save(obj);
          }
  
  
      }
  </code></pre>