nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined.

具体报错:Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
解决方案:
第一步:检查springboot与springcloud的版本是否统一(不统一,即使进行后续操作也会出现版本不兼容问题)
例如:
nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined._第1张图片
第二步:如果使用了alibaba的nacos则要排除其中的ribbon包
因为nacos中ribbon会造成loadbalancer包失效

 
 <dependency>
     <groupId>com.alibaba.cloudgroupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
     <exclusions>
         <exclusion>
             <groupId>org.springframework.cloudgroupId>
             <artifactId>spring-cloud-starter-netflix-ribbonartifactId>
         exclusion>
     exclusions>
 dependency>

第三步:添加loadbalancer包
完整pom文件如下


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        
        <version>2.6.3version>
        <relativePath/> 
    parent>
    <groupId>com.mallgroupId>
    <artifactId>mall-memberartifactId>
    <properties>
        <java.version>1.8java.version>
        
        <spring-cloud.version>2021.0.1spring-cloud.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-openfeignartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-loadbalancerartifactId>
        dependency>
    dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>
project>

你可能感兴趣的:(Java,java,spring,cloud,spring,boot)