title: Field book in com.example.BookProject.Servies.BookServies required a bean named 'book' that could not be found
body: <p><strong>I have this Problem with Spring-boot</strong>
  When Run the Server cannot run</p>
  <hr />
  <p>APPLICATION FAILED TO START</p>
  <hr />
  <p>Description:</p>
  <p>Field book in com.example.BookProject.Servies.BookServies required a bean named 'book' that could not be found.</p>
  <p>The injection point has the following annotations:
  - @org.springframework.beans.factory.annotation.Autowired(required=true)</p>
  <p>Action:</p>
  <p>Consider defining a bean named 'book' in your configuration.</p>
  <p>My pom.xml</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&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.4.1&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.BookProject&lt;/groupId&gt;
      &lt;artifactId&gt;BookProject&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;Book&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&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-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;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
  
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa --&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;version&gt;2.4.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.2.3.Final&lt;/version&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;version&gt;8.0.22&lt;/version&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>And My Entity Class</p>
  <pre><code>    package com.example.BookProject.Model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  
  @Entity
  @Table(name=&quot;book&quot;)
  public class Book {
      @Id
      private String id;
      
      @Column(unique = true,nullable = false ,name = &quot;BookTitle&quot;)
      private String title;
      
      @Column(name = &quot;BookDecription&quot;,unique = false, nullable = true)
      private String Decription;
  
      public Book() {
          super();
      }
  
      public Book(String id, String title, String decription) {
          super();
          this.id = id;
          this.title = title;
          Decription = decription;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public String getDecription() {
          return Decription;
      }
  
      public void setDecription(String decription) {
          Decription = decription;
      }
  
  }
  </code></pre>
  <p>My repository:</p>
  <pre><code>package com.example.BookProject.Repository;
      
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.stereotype.Repository;
      
      import com.example.BookProject.Model.Book;
      @Repository
      public interface BookRepo extends JpaRepository&lt;Book, String&gt; {
  
  }
  </code></pre>
  <p>My Servies:</p>
  <pre><code>    package com.example.BookProject.Servies;
  
  import java.util.List;
  
  import javax.transaction.Transactional;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.example.BookProject.Model.Book;
  import com.example.BookProject.Repository.BookRepo;
  
  @Service
  @Transactional
  public class BookServies {
      //i am inject BookRepo Here
      @Autowired
      public BookRepo book;
      
      //find all Book
      public List&lt;Book&gt; FindAllBook(){
          return book.findAll();
      }
      
      //find ById Book
      
      public Book FindById(String id)
      {
          return book.findById(id).get();
      }
      
      //Add new Book
      public void AddBook(Book newBook) {
          book.save(newBook);
          
      }
      
      public void DeleteBook(String id) {
          book.deleteById(id);
      }
      
  }
  </code></pre>
  <p>My Controller:</p>
  <pre><code>  package com.example.BookProject.Controller;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.example.BookProject.Model.Book;
  import com.example.BookProject.Servies.BookServies;
  
  @RestController
  @RequestMapping(value = &quot;api/book&quot;)
  public class BookController {
      //inject servies
      @Autowired
      private BookServies book;
      
      
      //find all book
      @GetMapping(value = &quot;/allBook&quot;)
      public List&lt;Book&gt; AllBook(){
          return book.FindAllBook();
      }
      
      //Add New Book Method
      @PostMapping(value = &quot;/addBook&quot;)
      public void AddBook(@RequestBody Book NewBook)
      {
          book.AddBook(NewBook);
          
      }
      
      //Find Book By Id
      @GetMapping(value = &quot;bookId/{id}&quot;)
      public Book FindBook(@PathVariable String id)
      {
          return book.FindById(id);
      }
      
      //DeleteBook By Id
      @GetMapping(value = &quot;/deleteId/{id}&quot;)
      public void DeleteBook(@PathVariable String id)
      {
          book.DeleteBook(id);
      }
      
  
  }
  </code></pre>