title: Spring: How to combine @RestClientTest with a RestTemplate with @Qualifier?
body: <p>I have changed a Spring Boot (2.1.4) service that consumes a <code>RestTemplate</code> to use a <code>@Qualifier</code>. Now my Test (with <code>@RestClientTest</code> and <code>@AutoConfigureWebClient</code>) fails because it can not resolve the bean. </p>
  
  <p>How do I fix this?</p>
  
  <p>The config:</p>
  
  <pre><code>  @Bean
    @Qualifier("eureka")
    @LoadBalanced
    RestTemplate eurekaRestTemplate() {
  </code></pre>
  
  <p>The service:</p>
  
  <pre><code>  public ClarkClient(
        @Qualifier("eureka") RestTemplate restTemplate, ClarkConfiguration configuration)
        throws URISyntaxException {
  </code></pre>
  
  <p>The test:</p>
  
  <pre><code>@ExtendWith({SpringExtension.class, MockitoExtension.class})
  @RestClientTest({CastorClient.class, CastorConfiguration.class})
  @AutoConfigureWebClient(registerRestTemplate = true)
  class CastorClientWebTest {
  
    @Autowired
    private CastorClient cut;
  
    @Autowired
    private MockRestServiceServer server;
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>[2019-04-16T14:02:22,614] [WARN ] [            ....AnnotationConfigApplicationContext] [refresh 557] : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'castorClient' defined in file [/home/martinsc/java/routing/route-testing-batch-manager/out/production/classes/com/tyntec/routetesting/batchmanager/core/clients/CastorClient.class]: 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: {@org.springframework.beans.factory.annotation.Qualifier(value=eureka)}
  </code></pre>