extension-configs 加载顺序优先级问题
如题: 我现在在nacos上增加了2个文件 1 a-dev.yml 2 db-dev.yml 代码中通过extension-configs 配置了2个文件 spring: application: name: @artifactId@ cloud: nacos: discovery: server-addr: ${NACOS-HOST:cloud-register}:${NACOS-PORT:8848} config: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: yml namespace: ${spring.profiles.active} extension-configs: - data-id: ${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} group: DEFAULT_GROUP refresh: true - data-id: db-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} group: DEFAULT_GROUP refresh: true profiles: active: dev
我在a-dev.yml db-dev.yml中分别都配置了spring.datasource 我在网上参考的看到extension-configs 越靠后的优先级越高 所以我理解的服务应该会连接db-dev.yml中配置的数据库 但现在测试发现连接的是a-dev.yml(通过mybatis-plus访问) 数据库:mysql nacos依赖:1.3.3 nacos服务:2.0.1
public void loadConfig() {
Properties globalProperties = buildGlobalNacosProperties();
MutablePropertySources mutablePropertySources = environment.getPropertySources();
List<NacosPropertySource> sources = reqGlobalNacosConfig(globalProperties,
nacosConfigProperties.getType());
for (NacosConfigProperties.Config config : nacosConfigProperties.getExtConfig()) {
List<NacosPropertySource> elements = reqSubNacosConfig(config,
globalProperties, config.getType());
sources.addAll(elements);
}
if (nacosConfigProperties.isRemoteFirst()) {
for (ListIterator<NacosPropertySource> itr = sources.listIterator(sources.size()); itr.hasPrevious();) {
mutablePropertySources.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, itr.previous());
}
} else {
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);
}
}
}
根据以上源码得知,extension-configs🈷️靠后的配置优先级越低
Thanks for your feedback and contribution. But the issue/pull request has not had recent activity more than 180 days. This issue/pull request will be closed if no further activity occurs 7 days later. We may solve this issue in new version. So can you upgrade to newest version and retry? If there are still issues or want to contribute again. Please create new issue or pull request again.