title: Why do we need to call Service layer using Interface instead of direct service class from controller in spring
body: <p>When spring was introduced its advice to use an interface between different layers like Controller,Service,DAO instead of directly calling them using actual class reference.</p>
  <p>In new age of Spring 5.x and Spring Boot 2.x do we need to still use interface between Controller and Service class. In my case I am developing a REST application with single GET method which call DB and do some business logic. So In my service I have only one method in this case still I do need to use ServiceInterface to call my actual ServiceImpl? what is best practice and is there any specific advantage of using ServiceInterface in this scenario?</p>
  <p>Below is Sample code without ServiceInterface</p>
  <pre><code>public class MyTestController{
  
   private MyTestServiceImpl myTestServiceImpl;
  
  public MyTestController(MyTestServiceImpl myTestServiceImpl){
        this.myTestServiceImpl = myTestServiceImpl;
  }
  
  @GetMapping(&quot;/test&quot;)
  public String getTestString(){
       myTestServiceImpl.getTestString();
  }
  }
  
  
  @Service
  public class MyTestServiceImpl(){
  
   private MyTestRepository myTestRepository;
  
  //constructor
  
  //Service method impl
  }
  
  </code></pre>