title: Spring Boot : required a bean named 'entityManagerFactory' that could not be found
body: <p>Error:</p>
  <blockquote>
  <p>Description:</p>
  <p>Field userRepository in nashtech.tiennguyenm3.config.DataSeedingListener required a bean of type 'nashtech.tiennguyenm3.dao.IUserRepository' that could not be found.</p>
  <p>Action:</p>
  <p>Consider defining a bean of type 'nashtech.tiennguyenm3.dao.IUserRepository' in your configuration.</p>
  </blockquote>
  <p>Code:</p>
  <pre><code>package nashtech.tiennguyenm3.musicstore;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication(scanBasePackages={&quot;nashtech.tiennguyenm3&quot;})
  public class MusicStoreApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MusicStoreApplication.class, args);
      }
  }
  </code></pre>
  <p>DataSeedingListener.java</p>
  <pre><code>package nashtech.tiennguyenm3.config;
  
  import java.util.HashSet;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationListener;
  import org.springframework.context.event.ContextRefreshedEvent;
  import org.springframework.security.crypto.password.PasswordEncoder;
  import org.springframework.stereotype.Component;
  
  import nashtech.tiennguyenm3.dao.IRoleRepository;
  import nashtech.tiennguyenm3.dao.IUserRepository;
  import nashtech.tiennguyenm3.model.Role;
  import nashtech.tiennguyenm3.model.User;
  
  @Component
  public class DataSeedingListener implements ApplicationListener&lt;ContextRefreshedEvent&gt; {
      
      @Autowired
      private IUserRepository userRepository;
  
      @Autowired
      private IRoleRepository roleRepository;
  
      @Autowired 
      private PasswordEncoder passwordEncoder;
  
      @Override
      public void onApplicationEvent(ContextRefreshedEvent arg0) {
          // Roles
          if (roleRepository.findByName(&quot;ROLE_ADMIN&quot;) == null) {
              roleRepository.save(new Role(&quot;ROLE_ADMIN&quot;));
          }
  
          if (roleRepository.findByName(&quot;ROLE_MEMBER&quot;) == null) {
              roleRepository.save(new Role(&quot;ROLE_MEMBER&quot;));
          }
  
          // Admin account
          if (userRepository.findByEmail(&quot;admin@gmail.com&quot;) == null) {
              User admin = new User();
              admin.setEmail(&quot;admin@gmail.com&quot;);
              admin.setPassword(passwordEncoder.encode(&quot;123456&quot;));
              HashSet&lt;Role&gt; roles = new HashSet&lt;&gt;();
              roles.add(roleRepository.findByName(&quot;ROLE_ADMIN&quot;));
              roles.add(roleRepository.findByName(&quot;ROLE_MEMBER&quot;));
              admin.setRoles(roles);
              userRepository.save(admin);
          }
  
          // Member account
          if (userRepository.findByEmail(&quot;member@gmail.com&quot;) == null) {
              User user = new User();
              user.setEmail(&quot;member@gmail.com&quot;);
              user.setPassword(passwordEncoder.encode(&quot;123456&quot;));
              HashSet&lt;Role&gt; roles = new HashSet&lt;&gt;();
              roles.add(roleRepository.findByName(&quot;ROLE_MEMBER&quot;));
              user.setRoles(roles);
              userRepository.save(user);
          }
      }
  }
  </code></pre>
  <p>IUserReponsitory.java</p>
  <pre><code>package nashtech.tiennguyenm3.dao;
  
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.stereotype.Repository;
  
  import nashtech.tiennguyenm3.model.User;
  
  @Repository
  public interface IUserRepository extends CrudRepository&lt;User, Integer&gt; {
      public User findByEmail(String email);
  }
  </code></pre>
  <p>application.properties</p>
  <pre><code># ===============================
  # DATASOURCE
  # ===============================
  
  # Set here configurations for the database connection
  
  # Connection url for the database &quot;mycontact&quot;
  spring.datasource.url=jdbc:mysql://localhost:8181/db_musicstore
  
  # MySQL username and password 
  spring.datasource.username=root
  spring.datasource.password=
  
  # Keep the connection alive if idle for a long time (needed in production)
  spring.datasource.dbcp.test-while-idle=true
  spring.datasource.dbcp.validation-query=SELECT 1
  
  # ===============================
  # JPA / HIBERNATE
  # ===============================
  
  # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
  # stripped before adding them to the entity manager).
  
  # Show or not log for each sql query
  spring.jpa.show-sql=true
  
  # Hibernate ddl auto (create, create-drop, update): with &quot;update&quot; the database
  # schema will be automatically updated accordingly to java entities found in
  # the project
  spring.jpa.hibernate.ddl-auto=update
  
  # Naming strategy
  spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
  
  # Allows Hibernate to generate SQL optimized for a particular DBMS
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  
  security.basic.enabled=false
  </code></pre>
  <p>When I add (scanBasePackages={&quot;nashtech.tiennguyenm3&quot;}) after @SpringBootApplication, this error occurs.</p>