title: Circular Dependency in Spring Boot
body: <p>I'm trying to use restTemplate in my bootspring project, when i compile giving me error like this:</p>
  
  <pre><code>There is a circular dependency between 4 beans in the application context:
  - courseController (field com.example.service.CourseService com.example.controller.CourseController.courseDAO)
  - courseServiceRest (field private com.example.dao.CourseDAO com.example.service.CourseServiceRest.courseDAO)
  - courseDAOImpl (field private org.springframework.web.client.RestTemplate com.example.dao.CourseDAOImpl.restTemplate)
  - studentDAOImpl (field private org.springframework.web.client.RestTemplate com.example.dao.StudentDAOImpl.restTemplate)
  - restTemplate
  </code></pre>
  
  <p>Here is my code below:</p>
  
  <p>I think because i have same @bean in StudenDAOImpl and CourseDAOImpl, because if i delete CourseDAOImpl compile success, the code is below:</p>
  
  <p>StudentDAOImpl code:</p>
  
  <pre><code>@Service
  public class StudentDAOImpl implements StudentDAO
  {
      @Autowired
      private RestTemplate restTemplate;
  
      @Bean
      public RestTemplate restTemplate(RestTemplateBuilder builder) {
         return builder.build();
      }
  
      @Override
      public StudentModel selectStudent (String npm)
      {
          StudentModel student = restTemplate.getForObject(url+npm, StudentModel.class);
          return student;
      }
  
      @Override
      public List&lt;StudentModel&gt; selectAllStudents ()
      {
         return null;
      }
  
  }
  </code></pre>
  
  <p>CourseDAOImpl code:</p>
  
  <pre><code>@Service
  public class CourseDAOImpl implements CourseDAO {
  
      @Autowired
      private RestTemplate restTemplate;
  
      @Bean
      public RestTemplate restTemplate(RestTemplateBuilder builder) {
          return builder.build();
      }
  
      @Override
      public CourseModel selectCourse(String id) {
          CourseModel course = restTemplate.getForObject(urlCourse+id, CourseModel.class);
          return course;
      }
  
      @Override
      public List&lt;CourseModel&gt; selectAllCourses() {   
          return null;    
      }
  }
  </code></pre>
  
  <p>Any answer? Thank you very much.</p>