Skip to content
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

Merged
merged 7 commits into from
Jul 6, 2023

Conversation

totalo
Copy link
Contributor

@totalo totalo commented Jun 27, 2023

开启 nacos.config.bootstrap.enable=true。NacosConfigLoader 单例后会有问题。

第一次加载AnnotationConfigApplicationContext时,nacosConfigProperties 还是都是默认的,这个时候去找NacosConfigLoader,没有,就初始化了,并且单例了。

第二次加载AnnotationConfigServletWebServerApplicationContext时候,nacosConfigProperties已经从 yaml 中拿到了配置的值了,但是NacosConfigLoader在第一个加载的时候已经初始化了,内部的NacosConfigProperties 是默认的没办法修改了。导致后续的configLoader.loadConfig()dataIds 的时候会为空,进行抛出异常.

或者说根据参数缓存一下NacosConfigLoader,而不是做一个单例。大佬们觉得怎么修复比较好呢?

不一致:
image

抛出的异常:
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]

@totalo totalo changed the title fix bug [ISSUE #293] Revert NacosConfigLoader non-singleton Jun 27, 2023
Copy link
Collaborator

@hujun-w-2 hujun-w-2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要删掉NacosConfigLoaderFactory转而使用new的方式来创建NacosConfigLoader

@totalo totalo changed the title [ISSUE #293] Revert NacosConfigLoader non-singleton [ISSUE #293] Fixed yaml configuration not working Jul 2, 2023
@totalo
Copy link
Contributor Author

totalo commented Jul 3, 2023

整体思路:由于第一初始化的的时候是默认的nacosConfigProperties和 standardEnv,而我们需要的是配置文件的配置以及将配置修改放入standardServeltEnv 中供@NacosValue 使用,由此将nacosConfigProperties和environment作为参数传递,而不是成员变量。

@hujun-w-2
Copy link
Collaborator

补充一下springboot场景、springcloud场景的测试过程

@totalo
Copy link
Contributor Author

totalo commented Jul 6, 2023

补充一下springboot场景、springcloud场景的测试过程

在本地重新打了一个包,并在 https://github.com/nacos-group/nacos-examples. 中对应的nacos-spring-boot-config-examplenacos-spring-cloud-config-example模块运行,配置正常拉取成功,并且支持动态刷新。

@hujun-w-2 hujun-w-2 merged commit 71db41f into nacos-group:master Jul 6, 2023
@totalo totalo deleted the fix-error branch July 6, 2023 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants