引入nacos 报错java.lang.IllegalStateException: Error processing condition on com.alibaba.cloud.nacos.loa

springboot项目引入nacos服务依赖报错,

springboot版本:2.7.4

spring-cloud版本2021.0.4

spring-cloud-alibaba版本2021.0.4.0

<!--nacos 服务注册发现-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

完整报错信息:

15:17:21:310 ERROR 15820 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Error processing condition on com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration.nacosLoadBalancer
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:193) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:153) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.23.jar:5.3.23]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.4.jar:2.7.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.4.jar:2.7.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.4.jar:2.7.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.4.jar:2.7.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.4.jar:2.7.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.4.jar:2.7.4]
	at com.JinyiItemApplication.main(JinyiItemApplication.java:12) ~[classes/:na]
Caused by: java.lang.IllegalStateException: @ConditionalOnMissingBean did not specify a bean using type, name or annotation and the attempt to deduce the bean's type failed
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.validate(OnBeanCondition.java:494) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:443) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:154) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	... 17 common frames omitted
Caused by: org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanTypeDeductionException: Failed to deduce bean type for com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration.nacosLoadBalancer
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:524) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanType(OnBeanCondition.java:513) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:436) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
	at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
	at java.base/java.lang.Class.forName(Class.java:398) ~[na:na]
	at org.springframework.boot.autoconfigure.condition.FilteringSpringBootCondition.resolve(FilteringSpringBootCondition.java:108) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.getReturnType(OnBeanCondition.java:532) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:520) ~[spring-boot-autoconfigure-2.7.4.jar:2.7.4]
	... 21 common frames omitted


Process finished with exit code 1

这段日志显示了一个Spring Boot应用程序在启动时遇到了错误。错误的核心是java.lang.IllegalStateException,这通常表明Spring Boot在处理条件注解时遇到了问题。具体来说,错误信息指出@ConditionalOnMissingBean注解没有正确指定一个bean的使用类型、名称或注解,并且在尝试推断bean类型时失败了。

具体的错误链如下:

  1. IllegalStateException: 由于@ConditionalOnMissingBean注解没有正确指定bean,导致Spring Boot无法确定是否应该创建这个bean。

  2. OnBeanCondition$BeanTypeDeductionException: Spring Boot尝试推断com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration.nacosLoadBalancer方法的返回类型时失败了。

  3. ClassNotFoundException: 无法找到org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer类,这通常是因为缺少相关的依赖库。

(1)  刚开始参考官方文档GitHub - alibaba/spring-cloud-alibaba: Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.

以为是版本问题

于是修改版本 为2.6.5,仍然报同样的错误

来来回回改了好几次版本,仍然报错

(2)  后来查了半天,仔细看报错信息,尝试引入依赖

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

于是再次启动项目,成功!

返回nacos网页管理页面,发现注册成功

总结:

要解决这个问题,可以尝试以下步骤:

  1. 确保你的项目包含了所有必要的依赖。根据错误信息,看起来是缺少了Spring Cloud LoadBalancer相关的依赖。你需要在你的pom.xmlbuild.gradle文件中添加相应的依赖。

  2. 检查com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration类中的nacosLoadBalancer方法,确保它返回的是一个有效的bean类型。

  3. 如果你正在使用Spring Cloud的版本管理工具(如Spring Cloud Release Train或Spring Cloud Platform),确保所有相关的Spring Cloud组件版本是兼容的。

  4. 清理并重新构建项目,有时候IDE或构建工具可能会缓存旧的依赖信息。

  5. 如果问题仍然存在,尝试查看Spring Boot和Spring Cloud的官方文档,或者在社区论坛和Stack Overflow上搜索类似问题。

  6. 考虑升级到最新版本的Spring Boot和Spring Cloud,因为新版本可能修复了你遇到的问题。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值