You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With Camden.SR2 if @EnableEurekaClient is on, but eureka.client.enabled=false, which is a totally valid use case (for example in a local dev profile when you don't want to connect to Eureka Server), this simple app throws an exception. This used to work in Brixton.
I believe this commit to remove the usage of deprecated constructor is the culprit: 856c471
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableEurekaClient
public class DemoSpringCloudEurekaBugApplication {
public class ClassThatUsesLoadbalancer {
private LoadBalancerClient loadBalancerClient;
public ClassThatUsesLoadbalancer(LoadBalancerClient loadBalancerClient) {
this.loadBalancerClient = loadBalancerClient;
}
public void doStuff() {
ServiceInstance serviceInstance = loadBalancerClient.choose("http://host/doStuff");
if (serviceInstance!=null) {
System.out.println("cool, there is a service instance, because Eureka discovery is enabled and the service is registered");
} else {
System.out.println("Oh no instance, because Eureka is disabled or there is no service matching. But this is ok");
}
}
}
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(DemoSpringCloudEurekaBugApplication.class, args);
ClassThatUsesLoadbalancer classThatUsesLoadbalancer = applicationContext.getBean(ClassThatUsesLoadbalancer.class);
classThatUsesLoadbalancer.doStuff();
}
@Bean
ClassThatUsesLoadbalancer classThatUsesLoadbalancer(LoadBalancerClient loadBalancerClient){
return new ClassThatUsesLoadbalancer(loadBalancerClient);
}
}
The exception:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ribbonLoadBalancingHttpClient' defined in org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration$HttpClientRibbonConfiguration: Unsatisfied dependency expressed through method 'ribbonLoadBalancingHttpClient' parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ribbonLoadBalancer' defined in org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ILoadBalancer]: Factory method 'ribbonLoadBalancer' threw exception; nested exception is 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: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:110)
at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:79)
at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:115)
at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getInstance(SpringClientFactory.java:111)
at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getLoadBalancer(SpringClientFactory.java:57)
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.getLoadBalancer(RibbonLoadBalancerClient.java:141)
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.getServer(RibbonLoadBalancerClient.java:130)
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(RibbonLoadBalancerClient.java:62)
at com.example.DemoSpringCloudEurekaBugApplication$ClassThatUsesLoadbalancer.doStuff(DemoSpringCloudEurekaBugApplication.java:24)
The text was updated successfully, but these errors were encountered:
After a bit of debugging and looking through the available properties on EurekaClientConfigBean
Looks like the only way to get the same behaviour as before is to remove eureka.client.enabled=false
and instead specify:
Specifically, add `@ConditionalOnBean(EurekaClient.class)`.
Fixes an issue where eureka and ribbon are on the classpath, eureka.client.enabled=false which would cause a bean not found exception.
fixesgh-1511
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
Then in application.properties file I added below mentioned property and it worked for me. Thanks @strelok1 for the hint. eureka.client.enabled=false
With Camden.SR2 if
@EnableEurekaClient
is on, buteureka.client.enabled=false
, which is a totally valid use case (for example in a local dev profile when you don't want to connect to Eureka Server), this simple app throws an exception. This used to work in Brixton.I believe this commit to remove the usage of deprecated constructor is the culprit: 856c471
The exception:
The text was updated successfully, but these errors were encountered: