title: How to fix "Field ... required a bean of type ... that could not be found" exception Spring Boot
body: <p>I am working with spring boot tutorial from <em>javabrains</em> and everything was clear until putting <code>CrudRepository</code> inside project. Below you can find my main class:</p>
  
  <pre><code>package pl.springBootStarter.app;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class CourseApiDataApplication
  {
      public static void main(String args[])
  {
      SpringApplication.run(CourseApiDataApplication.class,args);
  }
  }
  </code></pre>
  
  <p>Service class:</p>
  
  <pre><code>package pl.springBootStarter.app.topic;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  @Service
  public class TopicService
  {
      @Autowired
      private TopicRepository topicRepository;
  
      private List&lt;Topic&gt; topics =  new ArrayList&lt;&gt;(Arrays.asList(
              new Topic("spring","spring framework", "spring framework dectription"),
              new Topic("sprin","spring framework", "spring framework dectription"),
              new Topic("spri","spring framework", "spring framework dectription")));
  
      public  List&lt;Topic&gt; getAllTopics()
      {
      //    return topics;
      List&lt;Topic&gt; t = new ArrayList&lt;Topic&gt;();
      topicRepository.findAll().forEach(t::add);
      return t;
      }
  
      public Topic getTopic (String id)
      {
          return   topics.stream().filter( t -&gt; t.getId().equals(id)).findFirst().get();
      }
  
      public void addTopic(Topic topic) {
          topicRepository.save(topic);
      }
  
      public void updateTopic(Topic topic, String id)
      {
          topics.set(topics.indexOf(topics.stream().filter(t-&gt; t.getId().equals(id)).findFirst().get()), topic);
      }
  
      public void deleteTopic(String id)
      {
          topics.remove(topics.stream().filter(t -&gt; t.getId().equals(id)).findFirst().get());
      }
  }
  </code></pre>
  
  <p>And <code>Repository</code> interface:</p>
  
  <pre><code>package pl.springBootStarter.app.topic;
  
  import org.springframework.data.repository.CrudRepository;
  
  public interface TopicRepository extends CrudRepository&lt;Topic,String&gt;
  {
  
  }
  </code></pre>
  
  <p>When I run the app there is a problem with injection of <code>TopicRepository</code> into <code>topicRepository</code> field in <code>TopicService</code> class. I get following error:</p>
  
  <pre><code>Error starting ApplicationContext. To display the conditions report re-       run your application with 'debug' enabled.
  2019-05-01 10:33:52.206 ERROR 6972 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field topicRepository in pl.springBootStarter.app.topic.TopicService required a bean of type 'pl.springBootStarter.app.topic.TopicRepository' that could not be found.
  
  The injection point has the following annotations:
  -    @org.springframework.beans.factory.annotation.Autowired(required=true)
  </code></pre>
  
  <p>What could be the reason that Spring cannot do the autowiring?</p>