如何解决Spring Cloud LoadBalancerClient-Hoxton SR8-抛出错误
以前使用的是Spring Cloud Finchley.M9版本。我们按如下所示使用LoadBalancerClient。
'''import java.net.URI;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Component;
@Component
public class UriResolver {
private static final Logger LOGGER = LoggerFactory.getLogger(UriResolver.class);
private LoadBalancerClient loadBalancerClient;
@Autowired
public UriResolver(LoadBalancerClient loadBalancerClient) {
this.loadBalancerClient = loadBalancerClient;
}
public URI getBaseUri(String vendorName) {
ServiceInstance instance = loadBalancerClient.choose(vendorName);
URI uri = null;
if (!Objects.isNull(instance)) {
uri = instance.getUri();
LOGGER.debug("LoadBalancer Instance specific URI: " + instance.getUri());
LOGGER.debug("LoadBalancer Instance specific ServiceId: " + instance.getServiceId());
LOGGER.debug("LoadBalancer Instance specific Host: " + instance.getHost());
}
return uri;
}
}'''
现在,我们已经将Spring Cloud版本升级到Hoxton.SR8。在启动spring boot应用程序时,我们得到以下错误。
未加载'RibbonAutoConfiguration'中的Bean方法'loadBalancerClient',因为未匹配2的AllnestedConditions 2; RibbonAutoConfiguration.RibbonClassesConditions.RibbonPresent @ConditionalOnClass上的nestedCondition找不到所需的类'com.netflix.ribbon.Ribbon'; RibbonAutoConfiguration.RibbonClassesConditions.AsyncRestTemplatePresent @ConditionalOnClass上的nestedCondition找到了所需的类'org.springframework.web.client.AsyncRestTemplate'; RibbonAutoConfiguration.RibbonClassesConditions.RestTemplatePresent @ConditionalOnClass上的nestedCondition找到了所需的类'org.springframework.web.client.RestTemplate'; RibbonAutoConfiguration.RibbonClassesConditions.IClientPresent @ConditionalOnClass上的nestedCondition找不到必需的类'com.netflix.client.IClient'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。