sentinel持久化到nacos报错FactoryBean threw exception on object creation; nested exception is null
最新推荐文章于 2023-03-17 15:15:50 发布
最新推荐文章于 2023-03-17 15:15:50 发布
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

sentinel dashboard 能获取到nacos中的配置,但是无法将 sentinel dashboard 中调整的规则同步至nacos,是因为我用的nacos的命名空间为sentinel,不是public,在NaocosConfig配置类中,设置属性namespaces时,设置的不是命名空间名称。而是命名空间ID,故无法同步成功! 我们首先需要知道:在Sentinel Dashboard中配置规则之后重启应用就会丢失,所以实际生产环境中需要配置规则的持久化实现,Sentinel提供多种不同的数据源来持久化规则配置,包括redis、nacos、zookeeper等。............ FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanInitializationException: The security manager does not implement the WebSecurityManager interface. ShiroConfig报以上错误,往往是因粗心使用的类错误而导致。 我的错误: 其中的Defaul 问题就解决了,原因就是没有扫描到那个类嘛,那我们给他加上就好了,@EnableFeignClients中的basePackages只能扫描到Feign的注解。我仔细看了这个错误,发现是我这个FallbackFactory类,没有注入到spring中所以它连带着IServiceProvider没有创建bean成功。以上是服务降级的全部代码,然后我搜上面的报错,大部分都是在说我FallbackFactory类,没有加@Component这个注解,但我加了还是报这个错。是你原本这个类的包扫描路径。 记一个FeignClient无法注入bean的错误springcloud启动报错,错误log如下 springcloud启动报错,错误log如下 2020-06-03 16:25:21.551 WARN 28596 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 在@FeignClien(“XX”) 接口类中,检查每个方法的参数定义时: 是否有如下情形 @RequestMapping(value="/XXX/query", method = RequestMethod.GET) public PageResult<XXutionResp> query(@RequestParam(required = fals... org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleDaoImpl':Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.Be... 使用Feign请求nacos中注册的服务 问题描述: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0 原因分析: 解决方案: 设置@RequestParam Value值 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds1-sentinel-nacos-datasource': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException at org.springframework.beans.factory 在改造Sentinel sashboard实现和数据源持久化的过程中,遇到了热点规则及授权规则和单机模式无法兼容的问题,就是你改变了集群的热点规则及授权规则后,虽然持久化到数据源中,但是单机模式无法解析规则。使得规则无法打通。 究其原因,就是集群V2模式保存的数据,对了一级rule。所以保存和读取的时候就要稍微调整一下。 单机的loadConfig解析 [{"burstCount":0,"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCoun 在我们使用Sentinel做熔断限流等操作时,一些设置好的配置默认是存放在当前服的内存中的,那么也就意味着每次重启服务,这些配置好的配置就会消失。在我们搭建微服务架构做测试的时候不是很友好。大家都知道Sentinel提供了一些持久化方式,如持久化Nacos、本地JSON文件。这种方式虽然能解决持久化的操作,但是不能自动同步更新,也就是持久化配置写成什么样就是什么样,在程序启动后,无法动态更新到持久化存储中!当然能做到持久化Nacos或者本地JSON已经很不错了!如果作用做到这一步那么请见Sentin