nacos报错,.BeanCreationException: Error creating bean with name ‘nacosProperties‘ defined in class

错误码:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nacosProperties' defined in class path resource [com/alibaba/cloud/nacos/discovery/NacosDiscoveryAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.alibaba.cloud.nacos.NacosDiscoveryProperties] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at com.atguigu.guli.service.oss.ServiceOssApplication.main(ServiceOssApplication.java:19)

被nacos一个错误耽误了一天,很难受。错误类似于nacos在一个包中的某一个类找不到了,这个类我在实际测试的过程中出现好几次不同的类,都是nacos中的一个类。

但是我有一个完整的Maven下的nacos的包,没有网络错误。我就很奇怪,怎么会找不到呢?

主要错误如下:

.BeanCreationException: Error creating bean with name 'nacosProperties' defined in class path resource [com/alibaba/cloud//discovery/NacosDiscoveryAutoConfiguration.class]

这个类我明明就有,但是项目还是报错,启动不起来。

最后发现,这应该是nacos的一个bug。如果你把nacos的包放在c盘Maven仓库默认的地址下,就不会报错。(我们一般会把Maven仓库自定义到其他盘,防止c盘过大)

我还做了个实验,c盘和E盘的所有包都是一样的,在c盘就是正常的,其他盘就报错。

 


做以上写的前提是要配置好nacos配置,下面是基础配置,大佬可以跳过。


 

下载版本:nacos-server-1.1.4.zip 或 nacos-server-1.1.4.tar.gz,解压任意目录即可

  • Windows

启动:双击bin/startup.cmd运行文件

访问:http://localhost:8848/nacos

用户名密码:nacos/nacos

  • Linux/Unix/Mac

启动命令(standalone代表着单机模式运行,非集群模式)

启动命令:sh startup.sh -m standalone

 

 

 

1、引入依赖

service模块中配置Nacos客户端的pom依赖(我已经在父工程中定义的版本号,所以这里就不定义了,版本:<version>2.2.0.RELEASEE</version>)

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

2、添加服务配置信息

edu和oss微服务配置application.properties,在客户端微服务中添加注册Nacos服务的配置信息

#spring:
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848 # nacos服务地址

3、添加Nacos客户端注解

启动类中添加注解

@EnableDiscoveryClient

4、启动客户端微服务

启动注册中心,启动已注册的微服务,可以在Nacos服务列表中看到被注册的微服务

 

 

 

 

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
引用\[1\]:出现这种错误的原因,一开始我认为是Mybatis XML的问题,找了我好久,因为提示的信息大概就是数据库的连接不上,最后实在找不到办法了,我就把有关的文件一个个的看一下,最后发现了错误,原因是因为实体对象的的XML文件出错,where = #{} ,缺少了字段 。 引用\[2\]:启动是报下列错误,没有找到具体原因,网上也没搜索到具体答案,我的是未配置持久化时启动了,配置持久化后,点击shutdown.cmd关闭了,但之前启动的黑窗口未关闭,直接全部关闭重启,没有出现报错信息了; 。 引用\[3\]:最后是数据库链接地址与账号密码 #*************** Config Module Related Configurations ***************# ### If use MySQL as datasource: spring.datasource.platform=mysql ### Count of DB: db.num=1 ### Connect URL of DB: db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user.0=nacos db.password.0=nacos 。 问题:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'equipmentController' defined in file 回答: 出现这个错误的原因可能是在创建名为'equipmentController'的bean时出现了问题。根据提供的引用内容,我们无法确定具体的错误原因。引用\[1\]中提到了可能是Mybatis XML文件的问题,可能是实体对象的XML文件中缺少了字段。引用\[2\]中提到了可能是启动时的配置问题,可能是未正确配置持久化导致的。引用\[3\]中提到了可能是数据库连接地址和账号密码的问题。要解决这个错误,你可以检查Mybatis XML文件是否正确,确保实体对象的XML文件中没有缺少字段。同时,你还可以检查启动时的配置是否正确,确保已正确配置持久化。另外,还需要确保数据库连接地址和账号密码的配置正确。如果问题仍然存在,可能需要进一步检查代码和日志以找到具体的错误原因。 #### 引用[.reference_title] - *1* [org.springframework.beans.factory.BeanCreationException: Error creating bean with name](https://blog.csdn.net/qq_42547726/article/details/89431008)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘grpcSdkServ](https://blog.csdn.net/lddzyh/article/details/127449883)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值