[2021.x]Separate nacos ConfigService initialization from normal properties bean. (#3787)

pull/3791/head^2
Ken Liu 8 months ago committed by GitHub
parent 4079d321e9
commit 16ddf584c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -593,7 +593,7 @@ public class NacosConfigProperties {
}
}
private void enrichNacosConfigProperties(Properties nacosConfigProperties) {
protected void enrichNacosConfigProperties(Properties nacosConfigProperties) {
if (environment == null) {
return;
}
@ -603,7 +603,7 @@ public class NacosConfigProperties {
String.valueOf(v)));
}
private String resolveKey(String key) {
protected String resolveKey(String key) {
Matcher matcher = PATTERN.matcher(key);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {

@ -0,0 +1,44 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.configdata;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.alibaba.cloud.nacos.NacosConfigProperties;
/**
* Used for initialization of Nacos ConfigService.
*/
public class NacosConfigDataLoadProperties extends NacosConfigProperties {
private Map<String, String> config = new HashMap<>();
@Override
protected void enrichNacosConfigProperties(Properties nacosConfigProperties) {
config.forEach((k, v) -> nacosConfigProperties.putIfAbsent(resolveKey(k),
String.valueOf(v)));
}
Map<String, String> getConfig() {
return config;
}
void setConfig(Map<String, String> config) {
this.config = config;
}
}

@ -59,16 +59,12 @@ public class NacosConfigDataLocationResolver
* Prefix for Config Server imports.
*/
public static final String PREFIX = "nacos:";
private final Log log;
// support params
private static final String GROUP = "group";
// support params
private static final String REFRESH_ENABLED = "refreshEnabled";
private static final String PREFERENCE = "preference";
private final Log log;
public NacosConfigDataLocationResolver(DeferredLogFactory logFactory) {
this.log = logFactory.getLog(getClass());
@ -85,22 +81,22 @@ public class NacosConfigDataLocationResolver
BindHandler bindHandler = getBindHandler(context);
NacosConfigProperties nacosConfigProperties;
if (context.getBootstrapContext().isRegistered(NacosConfigProperties.class)) {
if (context.getBootstrapContext().isRegistered(NacosConfigDataLoadProperties.class)) {
nacosConfigProperties = context.getBootstrapContext()
.get(NacosConfigProperties.class);
.get(NacosConfigDataLoadProperties.class);
}
else {
nacosConfigProperties = binder
.bind("spring.cloud.nacos", Bindable.of(NacosConfigProperties.class),
.bind("spring.cloud.nacos", Bindable.of(NacosConfigDataLoadProperties.class),
bindHandler)
.map(properties -> binder
.bind(NacosConfigProperties.PREFIX,
.bind(NacosConfigDataLoadProperties.PREFIX,
Bindable.ofInstance(properties), bindHandler)
.orElse(properties))
.orElseGet(() -> binder
.bind(NacosConfigProperties.PREFIX,
Bindable.of(NacosConfigProperties.class), bindHandler)
.orElseGet(NacosConfigProperties::new));
.bind(NacosConfigDataLoadProperties.PREFIX,
Bindable.of(NacosConfigDataLoadProperties.class), bindHandler)
.orElseGet(NacosConfigDataLoadProperties::new));
}
return nacosConfigProperties;

Loading…
Cancel
Save