title: Eureka Client - can't autowire client (spring says there are 2 beans defined)
body: <p>I have an application that is a eureka discovery client.</p>
  
  <p>It registers with my Eureka server just fine.</p>
  
  <p>Sadly when I try to autowire the EurekaClient in any @Component or @Service class to fetch registry instance details, I'm told that I can't autowire as there are 2 bean definitions:</p>
  
  <p><a href="https://i.stack.imgur.com/aE5eW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aE5eW.png" alt="enter image description here"></a></p>
  
  <p>I don't know what is causing this. I have the following dependencies in my pom.</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-starter-eureka&lt;/artifactId&gt;
      &lt;exclusions&gt;
          &lt;exclusion&gt;
              &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
              &lt;artifactId&gt;jsr311-api&lt;/artifactId&gt;
          &lt;/exclusion&gt;
      &lt;/exclusions&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&gt;
  &lt;/dependency&gt;`
  </code></pre>
  
  <p>The exclusion in the first dependency is due to conflicts with the second.</p>
  
  <p>My app is a discovery enabled app through the following configuration class:</p>
  
  <pre><code>@Configuration
  @EnableDiscoveryClient
  public class EurekaDiscoveryConfiguration {
  }
  </code></pre>
  
  <p>I really don't understand why it thinks there are 2 beans matching that description.</p>
  
  <p>FWIW, strangely enough I <em>can</em> autowire it in classes that are not annotated with @Component or @Service... and they work - i've managed to get them returning instance info correctly.</p>
  
  <p>I have a feeling, and i've read a bit around it, that using jersey 2.0 for my services interferes with eureka. I might just swap to consul......</p>
  
  <p>Many thanks in advance for any advice.</p>
  
  <p>EDIT: (added test class)</p>
  
  <p>This doesn't tell you much - it's just the base application test</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class MyAppApplicationTest {
  
      @Test
      public void contextLoads() {
      }
  }
  </code></pre>
  
  <p>... lots of tests extend that class but it fails all by itself. It breaks trying to build the resource class that I've currently got the EurekaClient autowired in.</p>
  
  <p><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.discovery.EurekaClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></p>