title: Spring boot APPLICATION FAILED TO START because Autowired bean not found
body: <p>My app:-</p>
  
  <pre><code>    @SpringBootApplication
      @ComponentScan("fi.ma.vegshopping")
      @EnableJpaRepositories("fi.ma.vegshopping")
      @EntityScan(basePackages = "fi.ma.vegshopping")
      public class VegShoppingApplication {
  
          public static void main(String[] args) {
              SpringApplication.run(VegShoppingApplication.class, args);
          }
      }
  </code></pre>
  
  <p>Problemict class:-</p>
  
  <pre><code>import fi.ma.vegshopping.dao.AccountDAO;
  import fi.ma.vegshopping.entity.Account;
  
  @Service
  public class MyDBAuthenticationService implements UserDetailsService {
  
      @Autowired
      private AccountDAO accountDAO;
  
      @Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
          Account account = accountDAO.findAccount(username); 
          System.out.println("Account= " + account);
  
          if (account == null) {
              throw new UsernameNotFoundException("User " //
                      + username + " was not found in the database");
          }
  
          // EMPLOYEE,MANAGER,..
          String role = account.getUserRole();
  
          List&lt;GrantedAuthority&gt; grantList = new ArrayList&lt;GrantedAuthority&gt;();
  
          // ROLE_EMPLOYEE, ROLE_MANAGER
          GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_" + role);
  
          grantList.add(authority);
  
          boolean enabled = account.isActive();
          boolean accountNonExpired = true;
          boolean credentialsNonExpired = true;
          boolean accountNonLocked = true;
  
          UserDetails userDetails = (UserDetails) new User(account.getUserName(), //
                  account.getPassword(), enabled, accountNonExpired, //
                  credentialsNonExpired, accountNonLocked, grantList);
  
          return userDetails;
      }
  
  }
  </code></pre>
  
  <p>AccountDAO class:-</p>
  
  <pre><code>    package fi.ma.vegshopping.dao;
  
      import fi.ma.vegshopping.entity.Account;
  
      public interface AccountDAO {
          public Account findAccount(String userName ); 
      }
  </code></pre>
  
  <p>AccountDAOImpl class:-</p>
  
  <pre><code>    package fi.ma.vegshopping.impl;
  
      import javax.transaction.Transactional;
  
      import org.hibernate.Criteria;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.criterion.Restrictions;
      import org.springframework.beans.factory.annotation.Autowired;
  
      import fi.ma.vegshopping.dao.AccountDAO;
      import fi.ma.vegshopping.entity.Account;
  
  
      @Transactional
      public class AccountDAOImpl implements AccountDAO {
  
          @Autowired
          private SessionFactory sessionFactory;
  
          @Override
          public Account findAccount(String userName ) {
              Session session = sessionFactory.getCurrentSession();
              Criteria crit = session.createCriteria(Account.class);
              crit.add(Restrictions.eq("userName", userName));
              return (Account) crit.uniqueResult();
          }
      }
  </code></pre>
  
  <p>Error:-</p>
  
  <hr>
  
  <p>APPLICATION FAILED TO START</p>
  
  <hr>
  
  <p>Description:</p>
  
  <p>Field accountDAO in fi.ma.vegshopping.authentication.MyDBAuthenticationService required a bean of type 'fi.ma.vegshopping.dao.AccountDAO' that could not be found.</p>
  
  <p>Action:</p>
  
  <p>Consider defining a bean of type 'fi.ma.vegshopping.dao.AccountDAO' in your configuration.</p>