sentinel持久化到nacos报错FactoryBean threw exception on object creation; nested exception is null

本文解决了一个关于Spring Cloud Alibaba Sentinel与Nacos配置时出现的NullPointerException问题,通过添加用户名和密码解决了Sentinel无法正常从Nacos加载配置的问题。
摘要由CSDN通过智能技术生成
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds2-sentinel-nacos-datasource': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1827) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at com.alibaba.cloud.sentinel.custom.SentinelDataSourceHandler.registerBean(SentinelDataSourceHandler.java:203) ~[spring-cloud-starter-alibaba-sentinel-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at com.alibaba.cloud.sentinel.custom.SentinelDataSourceHandler.lambda$afterSingletonsInstantiated$0(SentinelDataSourceHandler.java:93) ~[spring-cloud-starter-alibaba-sentinel-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at java.util.TreeMap.forEach(TreeMap.java:1001) ~[na:1.8.0_65]
	at com.alibaba.cloud.sentinel.custom.SentinelDataSourceHandler.afterSingletonsInstantiated(SentinelDataSourceHandler.java:80) ~[spring-cloud-starter-alibaba-sentinel-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:914) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at com.lsp.sentinel.Sentinel_8401.main(Sentinel_8401.java:12) ~[classes/:na]
Caused by: java.lang.NullPointerException: null
	at java.util.Hashtable.put(Hashtable.java:459) ~[na:1.8.0_65]
	at java.util.Properties.setProperty(Properties.java:166) ~[na:1.8.0_65]
	at com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean.getObject(NacosDataSourceFactoryBean.java:70) ~[spring-cloud-alibaba-sentinel-datasource-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean.getObject(NacosDataSourceFactoryBean.java:34) ~[spring-cloud-alibaba-sentinel-datasource-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 20 common frames omitted

在采用sentinel持久化到nacos的时候,发现了报错信息,但是配置文件的信息和nacos上编写的json配置是对应的

spring.cloud.sentinel.datasource.ds2.nacos.server-addr=localhost:8848
#说明我们微服务名称是哪一个
spring.cloud.sentinel.datasource.ds2.nacos.data-id=cloudalibaba-sentinel-service-8401
#默认分组
spring.cloud.sentinel.datasource.ds2.nacos.group-id=DEFAULT_GROUP

#json串
spring.cloud.sentinel.datasource.ds2.nacos.data-type=json
#规则类型
spring.cloud.sentinel.datasource.ds2.nacos.rule-type=flow

在这里插入图片描述
但是就是报错在创建bean的时候报空了,但是配置文件以及连接什么的既然都没有问题,初步判断了下nacos和sentinel没有达到连接,有了这个想法就开始往这个想法里找错。
最终在发现是以前埋的一个坑,在刚开始下载nacos的时候配置文件修改了登录认证的操作,然后从此不管在nacos提供服务还是消费都需要带上username和password,这个也不例外。
最终修改配置文件

spring.cloud.sentinel.datasource.ds2.nacos.server-addr=localhost:8848
#说明我们微服务名称是哪一个
spring.cloud.sentinel.datasource.ds2.nacos.data-id=cloudalibaba-sentinel-service-8401
#默认分组
spring.cloud.sentinel.datasource.ds2.nacos.group-id=DEFAULT_GROUP
spring.cloud.sentinel.datasource.ds2.nacos.username=nacos
spring.cloud.sentinel.datasource.ds2.nacos.password=nacos
#json串
spring.cloud.sentinel.datasource.ds2.nacos.data-type=json
#规则类型
spring.cloud.sentinel.datasource.ds2.nacos.rule-type=flow

加上用户名和密码重新启动项目,发现就启动ok

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值