title: Spring boot Field required a bean of type that could not be found
body: <p>I'm going through the JPA starter tutorial for spring boot am struggling.
  I know the question has been asked sometimes here (<a href="https://stackoverflow.com/questions/42907553/field-required-a-bean-of-type-that-could-not-be-found-error-spring-restful-ap">&#39;Field required a bean of type that could not be found.&#39; error spring restful API using mongodb</a>)</p>
  
  <p>But those problems are a bit different from what I have.</p>
  
  <p>Structure</p>
  
  <pre><code>java
    |
    helloWorld
    |
    web/ -- HelloWorldController
    Application
    Customer
    CustomerRepository
    ServletInitializer
  </code></pre>
  
  <p>As you can see all my packages related to JPA are on the same level as my Application file . According to the tutorial (<a href="https://spring.io/guides/gs/accessing-data-jpa/" rel="noreferrer">https://spring.io/guides/gs/accessing-data-jpa/</a>) this should work</p>
  
  <p>My Application class</p>
  
  <pre><code>package helloWorld;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  import org.springframework.context.annotation.ComponentScan;
  
  @SpringBootApplication
  public class Application extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Autowired
      CustomerRepository customerRepository;
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  }
  </code></pre>
  
  <p>CustomerRepository</p>
  
  <pre><code>package helloWorld;
  
  
  import org.springframework.data.repository.CrudRepository;
  
  import java.util.List;
  
  public interface CustomerRepository extends CrudRepository&lt;Customer, Long&gt; {
  
      List&lt;Customer&gt; findByLastName(String lastName);
  }
  </code></pre>
  
  <p>When trying to use <code>@Autowired</code> I receive </p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field customerRepository in helloWorld.Application required a bean of type 'helloWorld.CustomerRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'helloWorld.CustomerRepository' in your configuration.
  </code></pre>
  
  <p>Also, adding <code>scanBasePackages={"helloWorld"})</code> to <code>@SpringBootApplication</code> does not help and from what I read it should also not be needed.</p>
  
  <p><strong><code>pom.xml</code>:</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;helloWorld.com.example&lt;/groupId&gt;
      &lt;artifactId&gt;helloWorld&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;fireCommerce&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;2.0.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-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&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-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&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;plugin&gt;
                  &lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;
                  &lt;artifactId&gt;azure-webapp-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.1.0&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;resourceGroup&gt;maven-projects&lt;/resourceGroup&gt;
                      &lt;appName&gt;${project.artifactId}-${maven.build.timestamp}&lt;/appName&gt;
                      &lt;region&gt;westus&lt;/region&gt;
                      &lt;javaVersion&gt;1.8&lt;/javaVersion&gt;
                      &lt;deploymentType&gt;war&lt;/deploymentType&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p><a href="https://github.com/xhallix/helloWorldExample" rel="noreferrer">link to the github project</a></p>