title: Parameter 0 of constructor in Controller required a bean of type Service class that could not be found
body: <hr>
  
  <p>APPLICATION FAILED TO START</p>
  
  <hr>
  
  <pre class="lang-java prettyprint-override"><code>Description:
  
  Parameter 0 of constructor in edu.rohit.circuitbreakclient.controller.CircuitBreakerController required a bean of type 'edu.rohit.circuitbreakclient.service.CircuitBreakerService$BookService' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'edu.rohit.circuitbreakclient.service.CircuitBreakerService$BookService' in your configuration.
  </code></pre>
  
  <p><code>CircuitBreakerService</code> is as below.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service 
  @Component 
  @SpringBootApplication(scanBasePackages={"edu.rohit.circuitbreakclient.service", "edu.rohit.circuitbreakclient.controller"})
  
  
      //CircuitBreakerClientApplication 
      package edu.rohit.circuitbreakclient;
  
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
  
      @EnableCircuitBreaker
      @SpringBootApplication(scanBasePackages= {"edu.rohit.circuitbreakclient.service", "edu.rohit.circuitbreakclient.controller"})
      public class CircuitBreakerClientApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(CircuitBreakerClientApplication.class, args);
      }
  
      }
  
      //CircuitBreakerController
      package edu.rohit.circuitbreakclient.controller;
  
       import org.springframework.beans.factory.annotation.Autowired;
       import org.springframework.web.bind.annotation.CrossOrigin;
       import org.springframework.web.bind.annotation.RequestMapping;
       import org.springframework.web.bind.annotation.RestController;
       import edu.rohit.circuitbreakclient.service.CircuitBreakerService.BookService;
      @RestController
      @CrossOrigin
      @RequestMapping("/read")
      public class CircuitBreakerController {
  
      BookService bookService;
  
      @Autowired
      CircuitBreakerController(BookService bs){
          this.bookService=bs;
      }
  
      @RequestMapping("/get")
      public String toRead() {
          return bookService.readingList();
        }
  
      }
  
      //BookingService
      package edu.rohit.circuitbreakclient.service;
  
      import java.net.URI;
      import org.springframework.stereotype.Component;
      import org.springframework.web.client.RestTemplate;
      import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
  
      public class CircuitBreakerService {
  
      //@Service
      @Component
      public class BookService {
  
        private final RestTemplate restTemplate;
  
        public BookService(RestTemplate rest) {
          this.restTemplate = rest;
        }
  
        @HystrixCommand(fallbackMethod = "reliable")
        public String readingList() {
          URI uri = URI.create("http://localhost:8060/recommended");
  
          return this.restTemplate.getForObject(uri, String.class);
        }
  
        public String reliable() {
          return "Cloud not navigate to Circuit Breaker Server";
        }
  
      }
  
      }
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre class="lang-xml prettyprint-override"><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 https://maven.apache.org/xsd/maven-4.0.0.xsd"&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.2.0.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;edu.rohit&lt;/groupId&gt;
      &lt;version&gt;1&lt;/version&gt;
      &lt;description&gt;Demo project for Spring Boot CircuitBreakerClient&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;spring-cloud.version&gt;2.1.3.RELEASE&lt;/spring-cloud.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-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&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.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-netflix-hystrix&lt;/artifactId&gt;
              &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-netflix-hystrix-dashboard&lt;/artifactId&gt;
              &lt;version&gt;${spring-cloud.version}&lt;/version&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;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;!-- &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt; --&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;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;artifactId&gt;CircuitBreakerClient&lt;/artifactId&gt;
      &lt;name&gt;CircuitBreakerClient&lt;/name&gt;
      &lt;/project&gt;
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>server.port=8061
  hystrix.command.default.circuitBreaker.requestVolumeThreshold=20
  hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=500
  </code></pre>