title: UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'userDAO'
body: <p>I am trying to connect backend and frontend two separate projects of eclipse spring maven. I have added dependency to do so. But when I write down validate credentials logic in Homecontroller.java, after running on server its showing this exception. Please help to resolve it I have tried many methods already please suggest.</p>
  
  <p><strong>HomeController.java</strong></p>
  
  <pre><code>package com.yogesh.shoponlinefrontend.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Required;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.yogesh.shoponlineback.dao.UserDAO;
  import com.yogesh.shoponlineback.model.User;
  
  @Controller
  public class HomeController {
  
  
  @Autowired
  UserDAO userDAO;
  
  
  @RequestMapping("/")
  public String homePage() {
      System.out.println("Executing  the method homePage");
      return "home";
  }
  
  @RequestMapping("/login")
  public ModelAndView showLoginPage() {
  
      ModelAndView mv = new ModelAndView("home");
      mv.addObject("msg", "You clicked login link");
      mv.addObject("showLoginPage", "true");
      return mv;
  }
  
  @RequestMapping("/register")
  public ModelAndView showRegistrationPage() {
      ModelAndView mv = new ModelAndView("home");
  
      mv.addObject("msg", "You clicked Registration link ");
  
      mv.addObject("showRegistrationPage", "true");
  
      return mv;
  }
  
  @RequestMapping("/validate")
  public ModelAndView validate(@RequestParam("id") String id, @RequestParam("password") String pwd) {
      System.out.println("In validate method");
      System.out.println("id: " + id);
      System.out.println("pwd: " + pwd);
      ModelAndView mv = new ModelAndView("home");
  
      if (userDAO.validate(id, pwd) != null) {
          mv.addObject("successMsg", "You logged in successfully");
      } else {
          mv.addObject("errorMsg", "Invalid Credentials..Please try again");
      }
  
      return mv;
  }
  
  }
  </code></pre>
  
  <p><strong>UserDAO.java</strong></p>
  
  <pre><code>package com.yogesh.shoponlineback.dao;
  
  import java.util.List;
  
  import com.yogesh.shoponlineback.model.User;
  
  public interface UserDAO {
  
  public List&lt;User&gt; list();
  
  public User get(String username);
  
  public User validate(String username, String password);
  
  public boolean save(User user);
  
  public boolean update(User user);
  }
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>package com.yogesh.shoponlineback.model;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import javax.validation.constraints.Max;
  import javax.validation.constraints.Min;
  
  import org.hibernate.validator.constraints.NotEmpty;
  import org.springframework.stereotype.Component;
  
  @Entity
  //cha
  @Table(name="USER")  
  @Component
  public class User {
  
  @Id
  private String username;
  
  @NotEmpty(message = "please enter your name")
  private String name;
  
  @Min(5)
  @Max(15)
  private String password;
  private String mobile;
  private String role;
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  
  public String getMobile() {
      return mobile;
  }
  
  public void setMobile(String mobile) {
      this.mobile = mobile;
  }
  
  public String getRole() {
      return role;
  }
  
  public void setRole(String role) {
      this.role = role;
  }
  
  }
  </code></pre>
  
  <p><strong>UserDAOImpl.java</strong></p>
  
  <pre><code>package com.yogesh.shoponlineback.daoimpl;
  
  import java.util.List;
  
  
  import org.hibernate.Query;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.yogesh.shoponlineback.dao.UserDAO;
  import com.yogesh.shoponlineback.model.User;
  
  @Service
  @Repository()
  public class UserDAOImpl implements UserDAO {
  
  
  @Autowired
  UserDAO userDAO;
  
  @Autowired
  private SessionFactory sessionFactory;
  public UserDAOImpl(SessionFactory sessionFactory) {
      this.sessionFactory = sessionFactory;
  }
  
  public UserDAOImpl() {
      // TODO Auto-generated constructor stub
  }
  
  @Transactional
  public List&lt;User&gt; list() {
      String hql = "from User";
      Query query = sessionFactory.getCurrentSession().createQuery(hql);
      return query.list();
  }
  
  @Transactional
  public User get(String username) {
      return (User) sessionFactory.getCurrentSession().get(User.class, username);
  }
  
  @Transactional
  public  User validate(String username, String password) {
      String hql = "from User WHERE username ='" + username + "' and password='" + password + "'";
      Query query = sessionFactory.getCurrentSession().createQuery(hql);
      return (User)query.uniqueResult();
  }
  
  @Transactional
  public boolean save(User user) {
      try {
          sessionFactory.getCurrentSession().save(user);
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
  
      return true;
  }
  
  @Transactional
  public boolean update(User user) {
      try {
          sessionFactory.getCurrentSession().update(user);
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
      return true;
  }
  
  }
  </code></pre>
  
  <p>:::::::::::::::::::::::::::::<strong>Exception trace</strong>::::::::::::::::::::::::::::::::::</p>
  
  <pre><code>INFO: FrameworkServlet 'dispatcher': initialization started
  Jan 10, 2017 3:19:22 PM **org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh
  INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Jan 10 15:19:22 IST 2017]; root of context hierarchy
  Jan 10, 2017 3:19:22 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
  INFO: Registering annotated classes: [class com.yogesh.shoponlinefrontend.config.AppConfig]
  Jan 10, 2017 3:19:23 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor &lt;init&gt;
  INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  Jan 10, 2017 3:19:23 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext refresh
  WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'userDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yogesh.shoponlineback.dao.UserDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  Jan 10, 2017 3:19:23 PM org.springframework.web.servlet.DispatcherServlet initServletBean
  SEVERE: Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'userDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yogesh.shoponlineback.dao.UserDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:592)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370)
      at `enter code here`org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754)
      at** org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:540)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
      at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      at javax.servlet.GenericServlet.init(GenericServlet.java:158)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4903)
  </code></pre>