-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #293] Fixed yaml configuration not working #293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要删掉NacosConfigLoaderFactory转而使用new的方式来创建NacosConfigLoader
整体思路:由于第一初始化的的时候是默认的nacosConfigProperties和 standardEnv,而我们需要的是配置文件的配置以及将配置修改放入standardServeltEnv 中供@NacosValue 使用,由此将nacosConfigProperties和environment作为参数传递,而不是成员变量。 |
补充一下springboot场景、springcloud场景的测试过程 |
在本地重新打了一个包,并在 https://github.com/nacos-group/nacos-examples. 中对应的 |
开启 nacos.config.bootstrap.enable=true。NacosConfigLoader 单例后会有问题。
第一次加载
AnnotationConfigApplicationContext
时,nacosConfigProperties
还是都是默认的,这个时候去找NacosConfigLoader
,没有,就初始化了,并且单例了。第二次加载
AnnotationConfigServletWebServerApplicationContext
时候,nacosConfigProperties
已经从 yaml 中拿到了配置的值了,但是NacosConfigLoader
在第一个加载的时候已经初始化了,内部的NacosConfigProperties
是默认的没办法修改了。导致后续的configLoader.loadConfig()
取dataIds
的时候会为空,进行抛出异常.或者说根据参数缓存一下NacosConfigLoader,而不是做一个单例。大佬们觉得怎么修复比较好呢?
不一致:
抛出的异常:
java.lang.IllegalArgumentException: 'value' must not be null at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.core.env.AbstractPropertyResolver.resolvePlaceholders(AbstractPropertyResolver.java:202) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.core.env.AbstractEnvironment.resolvePlaceholders(AbstractEnvironment.java:566) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE] at com.alibaba.boot.nacos.config.util.NacosConfigLoader.reqGlobalNacosConfig(NacosConfigLoader.java:120) ~[nacos-config-spring-boot-autoconfigure-0.2.12.jar:0.2.12] at com.alibaba.boot.nacos.config.util.NacosConfigLoader.loadConfig(NacosConfigLoader.java:69) ~[nacos-config-spring-boot-autoconfigure-0.2.12.jar:0.2.12] at com.alibaba.boot.nacos.config.autoconfigure.NacosConfigApplicationContextInitializer.initialize(NacosConfigApplicationContextInitializer.java:89) ~[nacos-config-spring-boot-autoconfigure-0.2.12.jar:0.2.12] at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:623) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE] at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]