title: Field todoService in com.springboot.todoController.TodoController required a bean of type 'com.springboot.todo.TodoService' that could not be found
body: <p>I am a new beginner in Spring boot...I encounter a problem When I run my controller, </p>
  
  <blockquote>
    <p>Description:</p>
    
    <p>Field todoService in com.springboot.todoController.TodoController
    required a bean of type 'com.springboot.todo.TodoService' that could
    not be found.</p>
    
    <p>Action:</p>
    
    <p>Consider defining a bean of type 'com.springboot.todo.TodoService' in
    your configuration.</p>
  </blockquote>
  
  <p>below is my code</p>
  
  <p><strong>Todo.java</strong></p>
  
  <pre><code>package com.springboot.todoBean;
  
  import java.util.Date;
  
  public class Todo {
      private int id;
      private String user;
  
      private String desc;
  
      private Date targetDate;
      private boolean isDone;
  
      public Todo() {}
  
      public Todo(int id, String user, String desc, Date targetDate, boolean isDone) {
          super();
          this.id = id;
          this.user = user;
          this.desc = desc;
          this.targetDate = targetDate;
          this.isDone = isDone;
      }
  
  
      public int getId() {
          return id;
      }
  
  
      public String getUser() {
          return user;
      }
  
  
      public String getDesc() {
          return desc;
      }
  
  
      public Date getTargetDate() {
          return targetDate;
      }
  
  
      public boolean isDone() {
          return isDone;
      }
  
  }
  </code></pre>
  
  <p><strong>TodoService.java</strong></p>
  
  <pre><code>package com.springboot.todo;
  
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  import org.springframework.stereotype.Service;
  
  import com.springboot.todoBean.Todo;
  
  @Service
  public class TodoService {
      private static List&lt;Todo&gt; todos = new ArrayList&lt;Todo&gt;();
      private static int todoCount = 3;
  
  
      static {
          todos.add(new Todo(1, "Jack", "Learn Spring MVC", new Date(), false));
          todos.add(new Todo(2, "Jack", "Learn Struts", new Date(), false));
          todos.add(new Todo(3, "Jill", "Learn hibernate", new Date(), false));
      }
  
      public List&lt;Todo&gt; retrieveTodos(String user){
          List&lt;Todo&gt; filteredTodos = new ArrayList&lt;Todo&gt;();
          for (Todo todo : todos) {
              if(todo.getUser().equals(user))
                  filteredTodos.add(todo);
          }
          return filteredTodos;
      }
  
      public Todo addTodo(String name, String desc,
              Date targetDate, boolean isDone) {
          Todo todo = new Todo(++todoCount, name, desc, targetDate, isDone);
          todos.add(todo);
          return todo;
      }
  
      public Todo retrievedTodo(int id) {
          for(Todo todo: todos) {
              if(todo.getId() == id)
                  return todo;    
          }
          return null;
      }
  }
  </code></pre>
  
  <p><strong>TodoController.java</strong></p>
  
  <pre><code>package com.springboot.todoController;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RestController;
  import com.springboot.todo.TodoService;
  import com.springboot.todoBean.Todo;
  
  @RestController
  public class TodoController {
  
      @Autowired
      private TodoService todoService;
  
      @GetMapping("/users/{name}/todos")
      public List&lt;Todo&gt; retrieveTodo(@PathVariable String name){
          return todoService.retrieveTodos(name);
      }
  
      public static void main(String[] args) throws Exception {
          SpringApplication.run(TodoController.class, args);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CkLWt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CkLWt.jpg" alt="enter image description here"></a>
  I have added the annotation @Service to the TodoService to tell spring boot it is a bean, but it still cannot recognise, could anyone tell me how to solve this problem? thanks</p>