I have an application that is a eureka discovery client.
It registers with my Eureka server just fine.
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:
I don't know what is causing this. I have the following dependencies in my pom.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>`
The exclusion in the first dependency is due to conflicts with the second.
My app is a discovery enabled app through the following configuration class:
@Configuration
@EnableDiscoveryClient
public class EurekaDiscoveryConfiguration {
}
I really don't understand why it thinks there are 2 beans matching that description.
FWIW, strangely enough I can 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.
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......
Many thanks in advance for any advice.
EDIT: (added test class)
This doesn't tell you much - it's just the base application test
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyAppApplicationTest {
@Test
public void contextLoads() {
}
}
... 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.
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)}