spring-cloud-gateway3.03 整合springcloudalibaba nacos出现的版本冲突问题

在项目中同时导了spring-cloud-gateway和spring-cloud-alibaba-nacos的依赖后,运行项目会无法启动,出现下面异常

2021-08-06 17:55:19.767  INFO 20168 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-06 17:55:19.772  WARN 20168 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loadBalancerWebClientBuilderBeanPostProcessor' defined in class path resource [org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerBeanPostProcessorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'loadBalancerWebClientBuilderBeanPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2021-08-06 17:55:19.792  INFO 20168 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-06 17:55:19.821 ERROR 20168 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method loadBalancerWebClientBuilderBeanPostProcessor in org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration required a bean of type 'org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction' in your configuration.


进程已结束,退出代码1

springboot版本为 2.5.3

springcloud版本为 2020.0.3

spring-cloud-alibaba版本为 2.2.6.RELEASE

项目的部分pom.xml如下

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

出现这个问题首先想到的是版本冲突

查看maven的结构发现nacos 会传递依赖spring-cloud-starter-ribbon这个依赖,而且版本是对应springcloudalibaba的版本而不是springcloud的版本所以导致了版本冲突

spring-cloud-gateway3.03 整合springcloudalibaba nacos出现的版本冲突问题

 解决方法:

1.使用exclusion排除nacos对ribbon的传递依赖

<dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
     <exclusions>
         <exclusion>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
         </exclusion>
     </exclusions>
</dependency>

2.刷新maven配置,启动项目

spring-cloud-gateway3.03 整合springcloudalibaba nacos出现的版本冲突问题

 项目可以正常启动,问题解决

新版本的版本冲突问题很常见,推荐大家还是使用稳定的h版本

上一篇:WebFlux使用ServerHttpRequest出现找不到构造


下一篇:Reactive Spring实战 -- 响应式MySql交互