1.版本:
<!-- nacos -->
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
springcloud:Hoxton.RELEASE
springboot:2.2.7.RELEASE
`Error creating bean with name 'ribbonServerList' defined in class path resource,错误如图
2.解决方法:
配置文件加入配置 ribbon.nacos.enabled=false
3.原因:
//nacos默认使用NacosRibbonClientConfiguration,加载ribbonServerList时没有发现IClientConfig,所以报错
//通过ConditionalOnRibbonNacos注解,发现设置ribbon.nacos.enabled=false,会取消加载NacosRibbonClientConfiguration
//取消后会使用RibbonClientConfiguration,而RibbonClientConfiguration已经配置了所有基本属性
4.解决步骤,可以不看
尝试手动注入,但调用Feign时报空指针异常;
@Configuration
class IClientConfigComponent {
@Bean
public IClientConfig iClientConfig() {
return new DefaultClientConfigImpl();
}
}
查看源码发现时因为许多基本属性没有设置,从OpenFeign注入的Bean赋值基本属性
@Configuration
class IClientConfigComponent {
@Bean
public IClientConfig iClientConfig() {
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.loadProperties("client");
config.set(CommonClientConfigKey.ConnectTimeout, 1000);
config.set(CommonClientConfigKey.ReadTimeout, 1000);
config.set(CommonClientConfigKey.GZipPayload, true);
return config;
}
}
重新启动,报Load balancer does not have available server for client: client,没有配置负载均衡。加上:
@Bean
public IRule ribbonRule(IClientConfig config) {
if (this.propertiesFactory.isSet(IRule.class, name)) {
return this.propertiesFactory.get(IRule.class, config, name);
}
ZoneAvoidanceRule rule = new ZoneAvoidanceRule();
rule.initWithNiwsConfig(config);
return rule;
}
还是不行,负载均衡找不到对应服务,点击报错发现nacos默认使用的是NacosRibbonClientConfiguration
设置ribbon.nacos.enabled=false,重启,成功;
5总结
问题虽然解决了,但可能还存在潜在问题,等系统学习了Springcloud负载均衡再自定义配置.....