title: Field itemRepository in HomePageController required a bean of type ItemRepository that could not be found
body: <p>I'm new to spring boot and have been trying to make simple REST web application.
  I followed steps as shown in different guides but i still get the same problem when i try to run application.</p>
  
  <p>This is the output i see everytime i try to run code</p>
  
  <pre><code>  .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v2.0.3.RELEASE)
  
  2018-07-06 10:47:44.768  INFO 11172 --- [           main] App.App                                  : Starting App on DESKTOP-OTCRH25 with PID 11172 (started by EhabArman-Notebook in E:\java workplace\eclipse-workplace\full)
  2018-07-06 10:47:44.784  INFO 11172 --- [           main] App.App                                  : No active profile set, falling back to default profiles: default
  2018-07-06 10:47:44.925  INFO 11172 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@75c072cb: startup date [Fri Jul 06 10:47:44 EEST 2018]; root of context hierarchy
  2018-07-06 10:47:46.785  INFO 11172 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2018-07-06 10:47:46.816  INFO 11172 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2018-07-06 10:47:46.816  INFO 11172 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
  2018-07-06 10:47:46.840  INFO 11172 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_171\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Program Files\Apache Software Foundation\apache-maven-3.5.4\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PostgreSQL\10\lib;C:\Program Files\PostgreSQL\10\bin;C:\Program Files\apache-log4j-2.11.0-bin\log4j-api-2.11.0.jar;C:\Program Files\apache-log4j-2.11.0-bin\log4j-corei-2.11.0.jar;C:\Program Files\Git\cmd;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Program Files\MySQL\MySQL Server 8.0\bin;;C:\Program Files\Microsoft VS Code\bin;C:\Users\EhabArman-Notebook\Desktop;;.]
  2018-07-06 10:47:46.985  INFO 11172 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2018-07-06 10:47:46.985  INFO 11172 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2060 ms
  2018-07-06 10:47:47.172  INFO 11172 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
  2018-07-06 10:47:47.177  INFO 11172 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2018-07-06 10:47:47.178  INFO 11172 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2018-07-06 10:47:47.179  INFO 11172 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2018-07-06 10:47:47.179  INFO 11172 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2018-07-06 10:47:47.221  WARN 11172 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homePage': Unsatisfied dependency expressed through field 'itemRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'App.components.repository.ItemRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  2018-07-06 10:47:47.224  INFO 11172 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  2018-07-06 10:47:47.247  INFO 11172 --- [           main] ConditionEvaluationReportLoggingListener : 
  
  Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  2018-07-06 10:47:47.390 ERROR 11172 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field itemRepository in App.components.controller.HomePage required a bean of type 'App.components.repository.ItemRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'App.components.repository.ItemRepository' in your configuration.
  </code></pre>
  
  <p>Here is pom.xml</p>
  
  <pre><code>&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;Test&lt;/groupId&gt;
    &lt;artifactId&gt;Full&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&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;2.0.3.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
  
    &lt;dependencies&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;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --&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;/dependency&gt;
  
  
  
  
      &lt;/dependencies&gt;
  
      &lt;properties&gt;
              &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XlZq3.png" rel="nofollow noreferrer">my classes and hierarchy</a></p>
  
  <p>App Class:</p>
  
  <pre><code>package App;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  
  
  @SpringBootApplication
  public class App {
  
      public static void main(String[] args) {
  
          SpringApplication.run(App.class, args);
      }
  }
  
  
  
  package App.components.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  import App.components.repository.*;
  </code></pre>
  
  <p>HomePage class:</p>
  
  <pre><code>import App.components.repository.*;
  
  
  @Controller
  public class HomePage {
  
      @Autowired
      private ItemRepository itemRepository;
  
  
      @RequestMapping("/homepage")
      public String getHomePage() {   
          return "homepage/homepage.html";
      }
  
  
  }
  </code></pre>
  
  <p>ItemRepository</p>
  
  <pre><code>package App.components.repository;
  
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.stereotype.Repository;
  
  import App.components.model.Item;
  
  @Repository
  public interface ItemRepository extends CrudRepository&lt;Item, Long&gt;{
  
  }
  </code></pre>
  
  <p>Item class:</p>
  
  <pre><code>package App.components.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  
  
  @Entity
  @Table(name = "item")
  public class Item {
  
      @Id
      @GeneratedValue
      @Column(name = "id")
      private int id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "quantity")
      private int quantity;
  
      @Column(name = "price")
      private int price;
  
  
      public Item() {}
  
      public Item(String name,int quantity ,int price) {
             this.name = name;
             this.quantity = quantity;
             this.price = price;
         }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getQuantity() {
          return quantity;
      }
  
      public void setQuantity(int quantity) {
          this.quantity = quantity;
      }
  
      public int getPrice() {
          return price;
      }
  
      public void setPrice(int price) {
          this.price = price;
      }
  
      public String toString() {
          return "[" + id + " " + name + " " + price + " " + quantity +"]";
      }
  
  }
  </code></pre>