title: Consider defining a bean of type 'com.repository.UserRepository' in your configuration
body: <p>Hi I am doing JPA and Hibernate configuration using Java configuration in spring boot and I am stuck it at this error for hours.
  Even though I have declared the UserRepository as bean still it is not able to get the repository.</p>
  
  <pre><code>package com.repository;
  
  @Repository
  public interface UserRepository extends JpaRepository&lt;User, Long&gt; {}
  </code></pre>
  
  <p>My service class which is using this repository:</p>
  
  <pre><code>package com.service;
  
  @Service
  public class AppointmentPaymentServiceImpl implements AppointmentPaymentService {
  
  @Autowired
  private UserRepository userRepository;
  ......
  ......
  }
  </code></pre>
  
  <p>My Database configuration:</p>
  
  <pre><code>package com.config;
  
  @Configuration
  @PropertySource(value = { "classpath:application.properties" })
  @EnableTransactionManagement
  @EnableJpaRepositories("com.repository.*")
  @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
  public class DBConfig {
  
  @Value("${spring.datasource.driver-class-name}")
  public String driver;
  
  @Value("${spring.datasource.url}")
  public String url;
  
  @Value("${spring.datasource.username}")
  public String username;
  
  @Value("${spring.datasource.password}")
  public String password;
  
  @Value("${spring.jpa.properties.hibernate.dialect}")
  public String dialect;
  
  @Value("${spring.jpa.hibernate.ddl-auto}")
  public String ddl;
  
  @Bean(name = "dataSource")
  public DriverManagerDataSource dataSource() {
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName(driver);
      dataSource.setUrl(url);
      dataSource.setUsername(username);
      dataSource.setPassword(password);
  
      return dataSource;
  }
  
  
  @Bean(name = "sessionFactory")
  public LocalSessionFactoryBean hibernateSessionFactory(DataSource dataSource) {
      LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
      sessionFactory.setDataSource(dataSource());
      sessionFactory.setPackagesToScan(new String[] { "com.model.*" });
      sessionFactory.setHibernateProperties(hibernateProperties());
      return sessionFactory;
  }
  
  
  @Bean
  HibernateTransactionManager transactionManagerHib(SessionFactory sessionFactory) {
      HibernateTransactionManager transactionManager = new HibernateTransactionManager();
      transactionManager.setSessionFactory(sessionFactory);
      return transactionManager;
  }
  
  /*@Bean
  @Qualifier(value = "entityManager")
  public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
      return entityManagerFactory.createEntityManager();
  }*/
  
  @Bean
  public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
      return new PersistenceExceptionTranslationPostProcessor();
  }
  
  @Bean
   public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  
  HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
   vendorAdapter.setDatabase(Database.MYSQL);
   vendorAdapter.setGenerateDdl(true);
  
   LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
   em.setDataSource(dataSource());
   em.setPackagesToScan("com.model.*");
  em.setJpaVendorAdapter(vendorAdapter);
   em.setJpaProperties(hibernateProperties());
  
   return em;
  }
  
  @Bean
   public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
   JpaTransactionManager transactionManager = new JpaTransactionManager();
   transactionManager.setEntityManagerFactory(emf);
  
   return transactionManager;
  }
  
  Properties hibernateProperties() {
      return new Properties() {
          {
              setProperty("hibernate.hbm2ddl.auto", ddl);
              setProperty("hibernate.connection.useUnicode", "true");
              setProperty("spring.jpa.hibernate.ddl-auto", ddl);
              setProperty("hibernate.dialect", dialect);
              setProperty("spring.jpa.properties.hibernate.dialect", dialect);
              setProperty("hibernate.globally_quoted_identifiers", "true");
              setProperty("hibernate.connection.CharSet", "utf8mb4");
              setProperty("hibernate.connection.characterEncoding", "utf8");
  
          }
      };
  }
  
  }
  </code></pre>
  
  <p>And this is my main class:</p>
  
  <pre><code>package com; 
  
  @SpringBootApplication
  @ComponentScan(basePackages = { "com.*"})
  @EnableCaching
  @Configuration
  @PropertySource({"classpath:logging.properties"})
  public class MainApplication {
  
  public static void main(String[] args) {
      SpringApplication.run(MainApplication.class, args);
  }
  
  }
  </code></pre>
  
  <p>My pom.xml contains these dependencies  for hibernate and jpa if I use only spring data jpa then hibernate-core 5.0.12.Final is imported by default which I do not want:</p>
  
  <pre><code>  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      .
      .
      .
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.2.10.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;5.2.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field userRepository in com.service.AppointmentPaymentServiceImpl required a bean of type 'com.repository.UserRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'com.repository.UserRepository' in your configuration.
  </code></pre>
  
  <p>My User Entity:</p>
  
  <pre><code>package com.model;
  
  @Entity
  @Table(name = "USER")
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class User implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue
  @Column(name = "id")
  private Long id;
  
  @NotNull
  @Column(name = "city_id")
  private Long cityId;
  
  @Column(name = "name")
  private String name;
  
  @Column(name = "age")
  private int age;
  
  @Column(name = "locality")
  private String locality;
  
  @Column(name = "gender")
  private String gender;
  
  }
  </code></pre>