title: could not found bean for MongoRepository (Spring Boot)
body: <p>I am using <code>spring boot</code> and <code>MongoDB</code>. </p>
  
  <pre><code>Spring version : 4.3.9
  
  Spring boot version : 1.5.4
  </code></pre>
  
  <p>I am creating a repository which implements <code>MongoRepository</code> <code>interface</code>, like below</p>
  
  <pre><code>import org.springframework.data.mongodb.repository.MongoRepository;
  import org.springframework.stereotype.Repository;
  
  @Repository
  public interface HotelRepository extends MongoRepository&lt;Hotel,String&gt; {
  }
  </code></pre>
  
  <p>But, whenever I am adding a dependency to HotelRepository compiler giving the error <code>Field hotelRepository in com.demo.HotelController required a bean of type 'com.demo.HotelRepository' that could not be found.</code></p>
  
  <pre><code>@RestController
  @RequestMapping("/hotel")
  public class HotelController {
  
      @Autowired
      private HotelRepository hotelRepository;
  
      @GetMapping("/all")
      public List&lt;Hotel&gt; getAllHotels(){
          return this.hotelRepository.findAll();
      }
  }
  </code></pre>
  
  <p>I've examine all the aspects from my side to resolve the error but all in vain. What I've R&amp;D.</p>
  
  <ul>
  <li>For <code>HotelRepository</code> there will be a default implementation provided out of the box. <a href="https://spring.io/guides/gs/accessing-data-mongodb/" rel="noreferrer">as per spring docs</a></li>
  <li>I've annotated the interface with <code>@Repository</code>, so no need to put <code>@Component</code></li>
  <li>Adding dependency from spring context using <code>@Autowired</code> annotation, So it should pick created bean from spring context.</li>
  <li>All the required files are in the same package, so no need to put <code>@ComponentScan</code></li>
  </ul>
  
  <p>Here is my main spring boot application class : </p>
  
  <pre><code>import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class MongoWithBootApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MongoWithBootApplication.class, args);
      }
  }
  </code></pre>
  
  <p><strong>application.properties :</strong> </p>
  
  <pre><code>spring.data.mongodb.host=localhost
  spring.data.mongodb.port=27017
  spring.data.mongodb.database=HotelDB
  </code></pre>
  
  <p><strong>Stack trace</strong> : </p>
  
  <pre><code>2017-07-10 13:25:12.485  INFO 4712 --- [           main] com.demo.MongoWithBootApplication        : Starting MongoWithBootApplication on KELLGGNCPU0313 with PID 4712 (D:\STS_WS\MongoWithBoot\target\classes started by mehrajuddin.malik in D:\STS_WS\MongoWithBoot)
  2017-07-10 13:25:12.487  INFO 4712 --- [           main] com.demo.MongoWithBootApplication        : No active profile set, falling back to default profiles: default
  2017-07-10 13:25:12.519  INFO 4712 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@13acb0d1: startup date [Mon Jul 10 13:25:12 IST 2017]; root of context hierarchy
  2017-07-10 13:25:13.448  INFO 4712 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  2017-07-10 13:25:13.456  INFO 4712 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2017-07-10 13:25:13.456  INFO 4712 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
  2017-07-10 13:25:13.541  INFO 4712 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2017-07-10 13:25:13.541  INFO 4712 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1025 ms
  2017-07-10 13:25:13.635  INFO 4712 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
  2017-07-10 13:25:13.637  INFO 4712 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2017-07-10 13:25:13.638  INFO 4712 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2017-07-10 13:25:13.638  INFO 4712 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2017-07-10 13:25:13.638  INFO 4712 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2017-07-10 13:25:13.673  WARN 4712 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hotelController': Unsatisfied dependency expressed through field 'hotelRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.demo.HotelRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  2017-07-10 13:25:13.675  INFO 4712 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  2017-07-10 13:25:13.684  INFO 4712 --- [           main] utoConfigurationReportLoggingInitializer : 
  
  Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2017-07-10 13:25:13.737 ERROR 4712 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field hotelRepository in com.demo.HotelController required a bean of type 'com.demo.HotelRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'com.demo.HotelRepository' in your configuration.
  </code></pre>
  
  <p><strong>pom.xml</strong> : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.demo&lt;/groupId&gt;
      &lt;artifactId&gt;MongoWithBoot&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;MongoWithBoot&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.4.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Could someone please help me out here what am I missing? </p>