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如下

        
            org.springframework.cloud
            spring-cloud-starter-gateway
        

        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        

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

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

spring-cloud-gateway3.03 整合springcloudalibaba nacos出现的版本冲突问题_第1张图片

 解决方法:

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


     com.alibaba.cloud
     spring-cloud-starter-alibaba-nacos-discovery
     
         
              org.springframework.cloud
              spring-cloud-starter-netflix-ribbon
         
     

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

spring-cloud-gateway3.03 整合springcloudalibaba nacos出现的版本冲突问题_第2张图片

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

3.查找资料发现在springcloud 2020版本中已经使用spring-cloud-loadbalancer作为负载均衡了,如果要使用负载均衡功能还需要引入loadbalancer依赖

        
            org.springframework.cloud
            spring-cloud-starter-loadbalancer
        

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