Search code examples
javaspring-bootnetflix-eureka

how to solve netflix eureka client error in spring boot 3.2.0 and java 17


I am trying to configure eureka client in my new spring boot 3.2.0 application using java 17 and getting the below error while running.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaClient' parameter 3: No qualifying bean of type 'com.netflix.discovery.shared.transport.jersey.TransportClientFactories<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

enter image description here

I am using the below maven dependency and no other configurations.

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
   <version>4.1.0</version>
</dependency>

Please note that if I remove this dependency I don't see any error.\

Main Class

@SpringBootApplication
public class SpringBoot3Java17Application {

    public static void main(String[] args) {
        SpringApplication.run(CommissionManagerApplication.class, args);
    }

}

application.properties: (and also need help in how the application tracks the eureka server running locally)

eureka.client.service-url.defaultZone=http://admin:alined@localhost:8761/eureka/

Application Started but not registering with Eureka: enter image description here

Eureka Server: enter image description here

Need assistance in configuring eureka netflix client with spring boot 3.2.0 and java 17

Thank you!


Solution

  • It was resolved in spring.cloud 2023.0.3, but I discovered a temporary alternative solution in previous discussion to autoconfiguration. It works for me. This problem occurs because Jersey is included as a dependency in the classpath.

    @EnableDiscoveryClient
    @Configuration
    public class EurekaClientConfig {
        @Bean
        @ConditionalOnClass(name = { "org.springframework.web.client.RestTemplate", "org.glassfish.jersey.client.JerseyClient" })
        @ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
        public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
            return new RestTemplateDiscoveryClientOptionalArgs(eurekaClientHttpRequestFactorySupplier);
        }
    
        @Bean
        @ConditionalOnClass(name = { "org.springframework.web.client.RestTemplate", "org.glassfish.jersey.client.JerseyClient" })
        @ConditionalOnMissingBean(value = { TransportClientFactories.class }, search = SearchStrategy.CURRENT)
        public RestTemplateTransportClientFactories restTemplateTransportClientFactories(RestTemplateDiscoveryClientOptionalArgs optionalArgs) {
            return new RestTemplateTransportClientFactories(optionalArgs);
        }
    }