title: Component annotation is not working properly
body: <p>I am new in spring and hibernate, all thing is working fine but only Component annotation is not working. Each time this error is coming - </p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.vc.teacher.db.dao.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>My Code is - </p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"&gt;
      &lt;display-name&gt;teacher&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;jsp/signin.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
      &lt;!-- Spring Configuration --&gt;
          &lt;servlet&gt;
              &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
              &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;/servlet&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
              &lt;url-pattern&gt;/&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;servlet-mapping&gt;
           &lt;servlet-name&gt;default&lt;/servlet-name&gt;
           &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;default&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.js&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;default&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.jpg&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;default&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.woff&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;default&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.ttf&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
  
       &lt;context-param&gt;
          &lt;param-name&gt;log4jXMLpath&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/log4j.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
          &lt;context-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring-servlet.xml&lt;/param-value&gt;
          &lt;/context-param&gt;
          &lt;listener&gt;
              &lt;listener-class&gt;
                  org.springframework.web.context.ContextLoaderListener
              &lt;/listener-class&gt;
          &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>application-context.xml</strong></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" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
      &lt;tx:annotation-driven /&gt;
      &lt;context:component-scan base-package="com.vc.teacher" /&gt;
  
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
          lazy-init="false"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.vc.teacher.entities.User&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/prop&gt;
                  &lt;!-- &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt; --&gt;
                  &lt;prop key="show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/teacher"&gt;&lt;/property&gt;
          &lt;property name="username" value="root"&gt;&lt;/property&gt;
          &lt;property name="password" value="root"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>**spring</p>
  
  <pre><code>-servlet.xml** 
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-4.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"&gt;
  
  &lt;context:component-scan base-package="com.vc.teacher.controller" /&gt;
  
  &lt;!-- Configuration defining views files --&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>UserDao class</strong></p>
  
  <pre><code>package com.vc.teacher.db.dao;
  
  import java.util.List;
  
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.springframework.stereotype.Component;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.vc.teacher.entities.User;
  
  @Component
  public class UserDao {
  
  
      @Autowired
      SessionFactory sessionFactory;
  
      public SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      @Transactional
      public User checkCreditionals(String email, String password){
          User user = null;
          Session session  =  sessionFactory.getCurrentSession();
          Query query =   session.createQuery("from User where email = '"+email+"' and password = '"+password+"'");
          List list   =   query.list();
          if(list.size()&gt;0)
              user =  (User)list.get(0);
  
          return user;
      }
  
      @Transactional
      public boolean registerUser(User user){
          boolean result = false;
          Session session = sessionFactory.getCurrentSession();
          try{
              user.setUserTypeId(2);
              session.save(user);
  
              result = true;
          } catch (Exception e){
              result = false;
              e.printStackTrace();
          }
  
          return result;
      }
  
  }
  </code></pre>
  
  <p><strong>Entity Class - User</strong></p>
  
  <pre><code>package com.vc.teacher.entities;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="user")
  public class User {
  
      @Id
      @GeneratedValue
      @Column(name="user_id")
      private int id;
      @Column(name="age")
      private int age;
      @Column(name="user_type_id")
      private int userTypeId;
      @Column(name="first_name")
      private String firstName;
      @Column(name="last_name")
      private String lastName;
      @Column(name="profession")
      private String profession;
      @Column(name="phone")
      private String phone;
      @Column(name="email")
      private String email;
      @Column(name="password")
      private String password;
      @Column(name="address")
      private String address;
      @Column(name="status")
      private String status;
  
  
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      }
  
      public int getUserTypeId() {
          return userTypeId;
      }
      public void setUserTypeId(int userTypeId) {
          this.userTypeId = userTypeId;
      }
      public String getFirstName() {
          return firstName;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      public String getLastName() {
          return lastName;
      }
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
      public String getProfession() {
          return profession;
      }
      public void setProfession(String profession) {
          this.profession = profession;
      }
      public String getPhone() {
          return phone;
      }
      public void setPhone(String phone) {
          this.phone = phone;
      }
      public String getEmail() {
          return email;
      }
      public void setEmail(String email) {
          this.email = email;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      public String getAddress() {
          return address;
      }
      public void setAddress(String address) {
          this.address = address;
      }
      public String getStatus() {
          return status;
      }
      public void setStatus(String status) {
          this.status = status;
      }
  
  }
  </code></pre>
  
  <p><strong>Controller class - AccountController</strong></p>
  
  <pre><code>package com.vc.teacher.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import com.vc.teacher.db.dao.UserDao;
  import com.vc.teacher.entities.User;
  
  @Controller
  public class AccountController {
  
     @Autowired
     UserDao userDao; 
  
      @RequestMapping("/login")
      public String loginUser(@RequestParam("email") String email,
              @RequestParam("password") String password, Model model) {
  
          User user = userDao.checkCreditionals(
                  email, password);
          if (user != null) {
              model.addAttribute("user", user);
              return "jsp/profile";
          } else {
              model.addAttribute("error", "Wrong creditionals");
              return "jsp/signin";
          }
  
      }
  
      @RequestMapping("/signUp")
      public String initilize(Model model) {
          model.addAttribute(new User());
          return "jsp/signup";
      }
  
      @RequestMapping(method = RequestMethod.POST, value = "/register")
      public String signUpUser(User user, RedirectAttributes attributes) {
          boolean result = false;
  
          user.setStatus("Deactive");
          result = userDao.registerUser(user);
  
          if (result == true) {
              attributes.addFlashAttribute("message", "You are ready to go now !");
              return "redirect:/signUp";
          } else {
              attributes.addFlashAttribute("message", "Something went wrong");
              return "redirect:/signUp";
          }
  
      }
  }
  </code></pre>