title: REST API Autowire remote or local implementation of a service automatically
body: <p>I have a REST API built on Spring Boot consisting of 2 seperate web services. I don't know if those two web services will be hosted on the same machine so I want to make remote and local implementation for all services. Example below:</p>
  
  <p>Local service implementation:</p>
  
  <pre><code>public class LocalExampleService implements ExampleService{
  
     public Item getItem(long id){
        //Get item using implementation from another local project
     }
  }
  </code></pre>
  
  <p>Remote service implementation:</p>
  
  <pre><code>public class RemoteExampleService implements ExampleService{
  
     @Value("${serviceURL}")
     private String serviceURL;
  
     public Item getItem(long id){
        //Get item calling remote service
     }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class MyController{
      @Autowired
      private ExampleService exampleService;
  }
  </code></pre>
  
  <p>Web service has many services with local and remote implementation and I want to let Spring know which type of implementation it should choose for all services.</p>
  
  <p>I've been thinking about putting url in properties file and during intialization the app would check whether properties contain url and then autowire service approprietly. But then I would have to write logic for every service autowiring.  </p>
  
  <p>What's the best option to autowire correct service implementation automatically?</p>