首页 > 解决方案 > Spring cloud Ribbon Zookeeper 中的自定义 Loadblancer 规则

问题描述

在使用ribbon-zookeeper-discovery 设置自定义负载均衡器规则时遇到问题,当前规则提供程序是ROUND_ROBIN、RANDOM 和STICKY,但是我想要自定义规则。没有办法自定义它,因此尝试覆盖 bean dependenciesBasedLoadBalancerZookeeperRibbonClientConfiguration当我尝试覆盖 bean 时,我得到以下错误。

Description:

Parameter 1 of method dependenciesBasedLoadBalancer in io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration required a bean of type 'com.netflix.loadbalancer.ServerList' that could not be found.


Action:

Consider defining a bean of type 'com.netflix.loadbalancer.ServerList' in your configuration.

因此,我尝试复制整个文件ZookeeperRibbonAutoConfiguration并进行自定义depdenciesBaseLoadBalancer,但最终出现以下错误。

Description:

Parameter 0 of method ribbonServerListFromDependencies in io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found.


Action:

Consider defining a bean of type 'com.netflix.client.config.IClientConfig' in your configuration.

为了解决 IClientConfig 问题,我尝试从创建 ICleanConfig 类型的 bean DefaultClientConfigImpl,现在以错误告终。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'masterSelectorRule' defined in file [kp-service-consumer\target\classes\io\github\kprasad99\consumer\MasterSelectorRule.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dependenciesBasedLoadBalancer' defined in class path resource [io/github/kprasad99/consumer/MasterZookeeperRibbonAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ILoadBalancer]: Factory method 'dependenciesBasedLoadBalancer' threw exception; nested exception is java.lang.RuntimeException: Exception while initializing NIWSDiscoveryLoadBalancer:null, niwsClientConfig:ClientConfig:IgnoreUserTokenInConnectionPoolForSecureClient:null, EnableMarkingServerDownOnReachingFailureLimit:null, DeploymentContextBasedVipAddresses:null, PoolMaxThreads:null, IsSecure:null, ConnectionPoolCleanerTaskEnabled:null, NFLoadBalancerPingInterval:null, NIWSServerListFilterClassName:null, FollowRedirects:null, StaleCheckingEnabled:null, BackoffTimeout:null, MaxAutoRetries:null, ConnectionManagerTimeout:null, NIWSServerListClassName:null, PoolKeepAliveTime:null, CustomSSLSocketFactoryClassName:null, ProxyPort:null, NFLoadBalancerClassName:null, KeyStore:null, Version:null, ForceClientPortConfiguration:null, SecurePort:null, EnablePrimeConnections:null, EnableConnectionPool:null, MaxTotalTimeToPrimeConnections:null, ServerDownFailureLimit:null, Port:null, NFLoadBalancerMaxTotalPingTime:null, ReadTimeout:null, ClientClassName:null, NFLoadBalancerPingClassName:null, MaxRetriesPerServerPrimeConnection:null, RulePredicateClasses:null, EnableGZIPContentEncodingFilter:null, VipAddressResolverClassName:null, ConnIdleEvictTimeMilliSeconds:null, GZipPayload:null, EnableZoneExclusivity:null, KeyStorePassword:null, PrimeConnectionsURI:null, PoolKeepAliveTimeUnits:null, AppName:null, MinPrimeConnectionsRatio:null, RequestIdHeaderName:null, EnableZoneAffinity:null, VipAddress:null, NFLoadBalancerStatsClassName:null, Linger:null, OkToRetryOnAllOperations:null, PrimeConnectionsClassName:null, ConnectionCleanerRepeatInterval:null, TrustStore:null, TrustStorePassword:null, MaxAutoRetriesNextServer:null, listOfServers:null, MaxTotalHttpConnections:null, ReceiveBufferSize:null, ProxyHost:null, ServerDownStatWindowInMillis:null, MaxTotalConnections:null, InitializeNFLoadBalancer:null, PrioritizeVipAddressBasedServers:null, RequestSpecificRetryOn:null, MaxConnectionsPerHost:null, ConnectTimeout:null, UseIPAddrForServer:null, PoolMinThreads:null, ServerListUpdaterClassName:null, SendBufferSize:null, TargetRegion:null, IsClientAuthRequired:null, ServerListRefreshInterval:null, MaxHttpConnectionsPerHost:null, IsHostnameValidationRequired:null, NFLoadBalancerRuleClassName:null
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1325) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1171) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:67) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at io.github.kprasad99.consumer.KpServiceConsumerApplication.main(KpServiceConsumerApplication.java:13) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dependenciesBasedLoadBalancer' defined in class path resource [io/github/kprasad99/consumer/MasterZookeeperRibbonAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ILoadBalancer]: Factory method 'dependenciesBasedLoadBalancer' threw exception; nested exception is java.lang.RuntimeException: Exception while initializing NIWSDiscoveryLoadBalancer:null, niwsClientConfig:ClientConfig:IgnoreUserTokenInConnectionPoolForSecureClient:null, EnableMarkingServerDownOnReachingFailureLimit:null, DeploymentContextBasedVipAddresses:null, PoolMaxThreads:null, IsSecure:null, ConnectionPoolCleanerTaskEnabled:null, NFLoadBalancerPingInterval:null, NIWSServerListFilterClassName:null, FollowRedirects:null, StaleCheckingEnabled:null, BackoffTimeout:null, MaxAutoRetries:null, ConnectionManagerTimeout:null, NIWSServerListClassName:null, PoolKeepAliveTime:null, CustomSSLSocketFactoryClassName:null, ProxyPort:null, NFLoadBalancerClassName:null, KeyStore:null, Version:null, ForceClientPortConfiguration:null, SecurePort:null, EnablePrimeConnections:null, EnableConnectionPool:null, MaxTotalTimeToPrimeConnections:null, ServerDownFailureLimit:null, Port:null, NFLoadBalancerMaxTotalPingTime:null, ReadTimeout:null, ClientClassName:null, NFLoadBalancerPingClassName:null, MaxRetriesPerServerPrimeConnection:null, RulePredicateClasses:null, EnableGZIPContentEncodingFilter:null, VipAddressResolverClassName:null, ConnIdleEvictTimeMilliSeconds:null, GZipPayload:null, EnableZoneExclusivity:null, KeyStorePassword:null, PrimeConnectionsURI:null, PoolKeepAliveTimeUnits:null, AppName:null, MinPrimeConnectionsRatio:null, RequestIdHeaderName:null, EnableZoneAffinity:null, VipAddress:null, NFLoadBalancerStatsClassName:null, Linger:null, OkToRetryOnAllOperations:null, PrimeConnectionsClassName:null, ConnectionCleanerRepeatInterval:null, TrustStore:null, TrustStorePassword:null, MaxAutoRetriesNextServer:null, listOfServers:null, MaxTotalHttpConnections:null, ReceiveBufferSize:null, ProxyHost:null, ServerDownStatWindowInMillis:null, MaxTotalConnections:null, InitializeNFLoadBalancer:null, PrioritizeVipAddressBasedServers:null, RequestSpecificRetryOn:null, MaxConnectionsPerHost:null, ConnectTimeout:null, UseIPAddrForServer:null, PoolMinThreads:null, ServerListUpdaterClassName:null, SendBufferSize:null, TargetRegion:null, IsClientAuthRequired:null, ServerListRefreshInterval:null, MaxHttpConnectionsPerHost:null, IsHostnameValidationRequired:null, NFLoadBalancerRuleClassName:null
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1305) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1144) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ILoadBalancer]: Factory method 'dependenciesBasedLoadBalancer' threw exception; nested exception is java.lang.RuntimeException: Exception while initializing NIWSDiscoveryLoadBalancer:null, niwsClientConfig:ClientConfig:IgnoreUserTokenInConnectionPoolForSecureClient:null, EnableMarkingServerDownOnReachingFailureLimit:null, DeploymentContextBasedVipAddresses:null, PoolMaxThreads:null, IsSecure:null, ConnectionPoolCleanerTaskEnabled:null, NFLoadBalancerPingInterval:null, NIWSServerListFilterClassName:null, FollowRedirects:null, StaleCheckingEnabled:null, BackoffTimeout:null, MaxAutoRetries:null, ConnectionManagerTimeout:null, NIWSServerListClassName:null, PoolKeepAliveTime:null, CustomSSLSocketFactoryClassName:null, ProxyPort:null, NFLoadBalancerClassName:null, KeyStore:null, Version:null, ForceClientPortConfiguration:null, SecurePort:null, EnablePrimeConnections:null, EnableConnectionPool:null, MaxTotalTimeToPrimeConnections:null, ServerDownFailureLimit:null, Port:null, NFLoadBalancerMaxTotalPingTime:null, ReadTimeout:null, ClientClassName:null, NFLoadBalancerPingClassName:null, MaxRetriesPerServerPrimeConnection:null, RulePredicateClasses:null, EnableGZIPContentEncodingFilter:null, VipAddressResolverClassName:null, ConnIdleEvictTimeMilliSeconds:null, GZipPayload:null, EnableZoneExclusivity:null, KeyStorePassword:null, PrimeConnectionsURI:null, PoolKeepAliveTimeUnits:null, AppName:null, MinPrimeConnectionsRatio:null, RequestIdHeaderName:null, EnableZoneAffinity:null, VipAddress:null, NFLoadBalancerStatsClassName:null, Linger:null, OkToRetryOnAllOperations:null, PrimeConnectionsClassName:null, ConnectionCleanerRepeatInterval:null, TrustStore:null, TrustStorePassword:null, MaxAutoRetriesNextServer:null, listOfServers:null, MaxTotalHttpConnections:null, ReceiveBufferSize:null, ProxyHost:null, ServerDownStatWindowInMillis:null, MaxTotalConnections:null, InitializeNFLoadBalancer:null, PrioritizeVipAddressBasedServers:null, RequestSpecificRetryOn:null, MaxConnectionsPerHost:null, ConnectTimeout:null, UseIPAddrForServer:null, PoolMinThreads:null, ServerListUpdaterClassName:null, SendBufferSize:null, TargetRegion:null, IsClientAuthRequired:null, ServerListRefreshInterval:null, MaxHttpConnectionsPerHost:null, IsHostnameValidationRequired:null, NFLoadBalancerRuleClassName:null
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 33 common frames omitted
Caused by: java.lang.RuntimeException: Exception while initializing NIWSDiscoveryLoadBalancer:null, niwsClientConfig:ClientConfig:IgnoreUserTokenInConnectionPoolForSecureClient:null, EnableMarkingServerDownOnReachingFailureLimit:null, DeploymentContextBasedVipAddresses:null, PoolMaxThreads:null, IsSecure:null, ConnectionPoolCleanerTaskEnabled:null, NFLoadBalancerPingInterval:null, NIWSServerListFilterClassName:null, FollowRedirects:null, StaleCheckingEnabled:null, BackoffTimeout:null, MaxAutoRetries:null, ConnectionManagerTimeout:null, NIWSServerListClassName:null, PoolKeepAliveTime:null, CustomSSLSocketFactoryClassName:null, ProxyPort:null, NFLoadBalancerClassName:null, KeyStore:null, Version:null, ForceClientPortConfiguration:null, SecurePort:null, EnablePrimeConnections:null, EnableConnectionPool:null, MaxTotalTimeToPrimeConnections:null, ServerDownFailureLimit:null, Port:null, NFLoadBalancerMaxTotalPingTime:null, ReadTimeout:null, ClientClassName:null, NFLoadBalancerPingClassName:null, MaxRetriesPerServerPrimeConnection:null, RulePredicateClasses:null, EnableGZIPContentEncodingFilter:null, VipAddressResolverClassName:null, ConnIdleEvictTimeMilliSeconds:null, GZipPayload:null, EnableZoneExclusivity:null, KeyStorePassword:null, PrimeConnectionsURI:null, PoolKeepAliveTimeUnits:null, AppName:null, MinPrimeConnectionsRatio:null, RequestIdHeaderName:null, EnableZoneAffinity:null, VipAddress:null, NFLoadBalancerStatsClassName:null, Linger:null, OkToRetryOnAllOperations:null, PrimeConnectionsClassName:null, ConnectionCleanerRepeatInterval:null, TrustStore:null, TrustStorePassword:null, MaxAutoRetriesNextServer:null, listOfServers:null, MaxTotalHttpConnections:null, ReceiveBufferSize:null, ProxyHost:null, ServerDownStatWindowInMillis:null, MaxTotalConnections:null, InitializeNFLoadBalancer:null, PrioritizeVipAddressBasedServers:null, RequestSpecificRetryOn:null, MaxConnectionsPerHost:null, ConnectTimeout:null, UseIPAddrForServer:null, PoolMinThreads:null, ServerListUpdaterClassName:null, SendBufferSize:null, TargetRegion:null, IsClientAuthRequired:null, ServerListRefreshInterval:null, MaxHttpConnectionsPerHost:null, IsHostnameValidationRequired:null, NFLoadBalancerRuleClassName:null
    at com.netflix.loadbalancer.DynamicServerListLoadBalancer.initWithNiwsConfig(DynamicServerListLoadBalancer.java:133) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    at com.netflix.loadbalancer.DynamicServerListLoadBalancer.<init>(DynamicServerListLoadBalancer.java:99) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    at org.springframework.cloud.zookeeper.discovery.dependency.DependenciesBasedLoadBalancer.<init>(DependenciesBasedLoadBalancer.java:50) ~[spring-cloud-zookeeper-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration.dependenciesBasedLoadBalancer(MasterZookeeperRibbonAutoConfiguration.java:71) ~[classes/:na]
    at io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration$$EnhancerBySpringCGLIB$$48a8583d.CGLIB$dependenciesBasedLoadBalancer$5(<generated>) ~[classes/:na]
    at io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration$$EnhancerBySpringCGLIB$$48a8583d$$FastClassBySpringCGLIB$$295e7f78.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at io.github.kprasad99.consumer.MasterZookeeperRibbonAutoConfiguration$$EnhancerBySpringCGLIB$$48a8583d.dependenciesBasedLoadBalancer(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_172]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_172]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_172]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_172]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 34 common frames omitted
Caused by: java.lang.RuntimeException: Error initializing load balancer
    at com.netflix.loadbalancer.BaseLoadBalancer.initWithNiwsConfig(BaseLoadBalancer.java:227) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    at com.netflix.loadbalancer.DynamicServerListLoadBalancer.initWithNiwsConfig(DynamicServerListLoadBalancer.java:105) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    ... 47 common frames omitted
Caused by: java.lang.NullPointerException: null
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_172]
    at java.lang.Class.forName(Class.java:264) ~[na:1.8.0_172]
    at com.netflix.client.ClientFactory.instantiateInstanceWithClientConfig(ClientFactory.java:202) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    at com.netflix.loadbalancer.BaseLoadBalancer.initWithNiwsConfig(BaseLoadBalancer.java:221) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
    ... 48 common frames omitted

如何添加自定义负载均衡器规则。

标签: spring-cloudspring-cloud-netflixnetflix-ribbonspring-cloud-zookeeper

解决方案


Fixed the issue, instead of creating the bean with default constructor, created with default value with serviceId and namesapce, as shown below.

  @Bean
    public IClientConfig ribbonClientConfig() {
        return DefaultClientConfigImpl.getClientConfigWithDefaultValues(serviceId, DEFAULT_NAMESPACE);
    }

推荐阅读