spring-cloud-netflix: Application fails to start due to missing AbstractDiscoveryClientOptionalArgs bean
After updating Spring-Cloud from 2022.0.2 to 2022.0.3, our application failed to start:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field optionalArgs in org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration required a bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' in your configuration.
Our application is a mix of spring-boot web application and our internal core that relies on Grizzly and therefore ships org.glassfish.jersey.client.JerseyClient as a dependency. Besides the fact that this is a regression, I’m wondering what’s the proper way to configure the eureka client if a JerseyClient is on the classpath?
As a workaround I created the following configuration class
@Profile("dev")
@Configuration
public class DiscoveryClientOptionalArgConfiguration {
@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);
}
}
However, this should work out of the box with auto-configuration as it did before.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 22 (3 by maintainers)
Commits related to this issue
- Remove dependency on JereseyClient class (#4185) — committed to ZIRAKrezovic/spring-cloud-netflix by ZIRAKrezovic 3 years ago
- Remove dependency on JereseyClient class (#4185) — committed to ZIRAKrezovic/spring-cloud-netflix by ZIRAKrezovic 3 years ago
- Allow disabling the under the hood use of JerseyClient with Eureka Client. Fixes gh-4185. — committed to erichaagdev/spring-cloud-netflix by OlgaMaciaszek 2 years ago
@Shapoval1van The auto-configuration happens inside the spring-cloud-netflix-eureka-client: https://github.com/spring-cloud/spring-cloud-netflix/blob/v4.0.3/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java#L67
There you can see that the default
RestTemplateDiscoveryClientOptionalArgsis not configured when you haveorg.glassfish.jersey.client.JerseyClienton the classpath. My workaround above configures the default behavior even though JerseyClient is on the classpath, as I didn’t want a discovery client based on Jersey but onRestTemplate. However, if you want a Jersey discovery client, there isJersey3DiscoveryClientOptionalArgswhich is shipped as part ofcom.netflix.eureka:eureka-client-jersey3dependency. However, that dependency is only shipped as part ofspring-cloud-starter-netflix-serverand not when you actually need it inspring-cloud-starter-netflix-eureka-clientSame problem
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.netflix.eureka.CloudEurekaClient.getApplications()" because the return value of "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient()" is null at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:83) ~[spring-cloud-netflix-eureka-client-4.1.1.jar:4.1.1] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:66) ~[spring-cloud-netflix-eureka-client-4.1.1.jar:4.1.1] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:89) ~[spring-cloud-netflix-eureka-client-4.1.1.jar:4.1.1] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288) ~[spring-context-6.1.6.jar:6.1.6] ... 13 common frames omittedany update, the issue fixed ?
Same problem with SpringBoot 3.1.1 and SpringCloud 2022.0.3
However i tried this eureka client cloned from here: repository The service registers correctly and works. The versions are the same.