title: Unable to autowire RestTemplate for unit test
body: <p>I have a service which uses an autowired instance of <code>RestTemplate</code> like below</p>
  
  <pre><code>@Service
  class SomeAPIService {
      private RestTemplate restTemplate;
  
      SomeAPIService(RestTemplate restTemplate) {
          this.restTemplate = restTemplate;
          this.restTemplate.setRequestFactory(HttpUtils.getRequestFactory());
      }
  }
  </code></pre>
  
  <p>Everything runs fine in non-test environment. But when I try to run following unit test in test profile, it starts complaining about unable to autowire rest template.</p>
  
  <pre><code>@RunWith( SpringJUnit4ClassRunner.class )
  @SpringBootTest(classes = MyApplication.class, webEnvironment = RANDOM_PORT, properties = "management.port:0")
  @ActiveProfiles(profiles = "test")
  @EmbeddedPostgresInstance(flywaySchema = "db/migration")
  public abstract class BaseTest {
  }
  
  @SpringBootTest(classes = SomeAPIService.class)
  public class SomeAPIServiceTest extends BaseTest {
      @Autowired
      SomeAPIService someAPIService;
  
      @Test
      public void querySomeAPI() throws Exception {
          String expected = someAPIService.someMethod("someStringParam");
      }
  }
  </code></pre>
  
  <p>Following is the detailed exception -</p>
  
  <blockquote>
    <p>Caused by:
    org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'someAPIService': Unsatisfied dependency
    expressed through constructor parameter 0; nested exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type 'org.springframework.web.client.RestTemplate'
    available: expected at least 1 bean which qualifies as autowire
    candidate. Dependency annotations: {}</p>
  </blockquote>
  
  <p>Any clues?</p>