Describe the bug
Spring Boot 3.0.0-RC2
<spring-cloud.version>2022.0.0-RC2</spring-cloud.version>
When running a native compiled app with Eureka enabled as client, the application fails to start with the following error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servicesController':
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'compositeDiscoveryClient':
Unsatisfied dependency expressed through method 'compositeDiscoveryClient' parameter 0: Error creating bean with name
'discoveryClient': Unsatisfied dependency expressed through method 'discoveryClient' parameter 0: No qualifying bean of type
'com.netflix.discovery.EurekaClient' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {}
Sample https://github.com/iromu/native-eureka-client/tree/3.0.x
Comment From: Jamby93
Same issue here. tested on Spring Boot 3.0.1 Spring Cloud 2022.0.0, spring-cloud-starter-netflix-eureka-client 4.0.0.
Running the built jar with a JDK gives no error, but if it is run with spring.aot.enabled=true
or the native image, it gives out the reported error.
Comment From: jesussaad
same case of @Jamby93
Comment From: Jamby93
Actually I ended up copy-pasting the beans definition from the EurekaClientAutoConfiguration. I'm not exactly sure how the @ConditionalOnRefreshScope
behaves with native/AOT compilation, but at least in this way I got it working in native mode.
@Autowired
private ApplicationContext context;
@Autowired
private AbstractDiscoveryClientOptionalArgs<?> optionalArgs;
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
TransportClientFactories<?> transportClientFactories) {
return new CloudEurekaClient(manager, config, transportClientFactories, this.optionalArgs, this.context);
}
@Bean
@ConditionalOnMissingBean(value = ApplicationInfoManager.class, search = SearchStrategy.CURRENT)
public ApplicationInfoManager eurekaApplicationInfoManager(EurekaInstanceConfig config) {
InstanceInfo instanceInfo = new InstanceInfoFactory().create(config);
return new ApplicationInfoManager(config, instanceInfo);
}
@Bean
@ConditionalOnMissingBean(value = EurekaRegistration.class, search = SearchStrategy.CURRENT)
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager,
@Autowired(required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager).with(eurekaClient)
.with(healthCheckHandler).build();
}
Comment From: aaronmaj
Same case as @Jamby93 but the proposed workaround is not working for me
Comment From: stefanof95
The solution provided by @Jamby93 works adding @Primary on eurekaRegistration bean (change bean name to avoid conflicts with spring eureka auto configuration)
Comment From: OlgaMaciaszek
@iromu @stefanof95 @aaronmaj have you set spring.cloud.refresh.enabled
to false
as indicated in the docs in your projects? I can see it's not been set in the sample. It should work OOTB then.
Comment From: dbamberghi
@iromu @stefanof95 @aaronmaj have you set
spring.cloud.refresh.enabled
tofalse
as indicated in the docs in your projects? I can see it's not been set in the sample. It should work OOTB then.
After setting the indicated property, when launch the native program returns this error
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'serviceId' cannot be found on object of type 'org.springframework.cloud.netflix.eureka.EurekaServiceInstance' - maybe not public or not valid?
Comment From: OlgaMaciaszek
I have run the linked sample (btw., Boot and Cloud versions are outdated in this sample, but it works anyway) as a native image after disabling refresh. The app ran without errors and I was also able to call both endpoints without facing any issues. @dbamberghi , if you are still experiencing issues, please provide a minimal, complete, verifiable example that reproduces the issue.
Comment From: dbamberghi
I have run the linked sample (btw., Boot and Cloud versions are outdated in this sample, but it works anyway) as a native image after disabling refresh. The app ran without errors and I was also able to call both endpoints without facing any issues. @dbamberghi , if you are still experiencing issues, please provide a minimal, complete, verifiable example that reproduces the issue.
I started an instance of Eureka (again with springboot3). Compiled the project consisting of the Gateway module and Eureka client. A few seconds after start-up, the error message 'failed refresh' appears with the message posted above.
Could this be a problem with the gateway module?
Comment From: OlgaMaciaszek
Thanks, @dbamberghi - I was able to reproduce it. It seems to only happen with both EurekaClient and Gateway Route Locator on. Will provide a fix.