use of org.springframework.boot.env.OriginTrackedMapPropertySource in project dynamic-tp by dromara.
the class ZkConfigEnvironmentProcessor method createZkPropertySource.
private void createZkPropertySource(ConfigurableEnvironment environment, Map<Object, Object> properties) {
MutablePropertySources propertySources = environment.getPropertySources();
OriginTrackedMapPropertySource zkSource = new OriginTrackedMapPropertySource(ZK_PROPERTY_SOURCE_NAME, properties);
propertySources.addLast(zkSource);
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project nacos by alibaba.
the class NacosAutoRefreshPropertySourceLoader method load.
@Override
public List<PropertySource<?>> load(String name, Resource resource) throws IOException {
holder = resource;
Map<String, ?> tmp = loadProperties(resource);
properties.putAll(tmp);
try {
WatchFileCenter.registerWatcher(EnvUtil.getConfPath(), new FileWatcher() {
@Override
public void onChange(FileChangeEvent event) {
try {
Map<String, ?> tmp1 = loadProperties(holder);
properties.putAll(tmp1);
} catch (IOException ignore) {
}
}
@Override
public boolean interest(String context) {
return StringUtils.contains(context, "application.properties");
}
});
} catch (NacosException ignore) {
}
if (properties.isEmpty()) {
return Collections.emptyList();
}
return Collections.singletonList(new OriginTrackedMapPropertySource("nacos_application_conf", properties));
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project nacos by alibaba.
the class StartingApplicationListener method loadPreProperties.
private void loadPreProperties(ConfigurableEnvironment environment) {
try {
SOURCES.putAll(EnvUtil.loadProperties(EnvUtil.getApplicationConfFileResource()));
environment.getPropertySources().addLast(new OriginTrackedMapPropertySource(NACOS_APPLICATION_CONF, SOURCES));
registerWatcher();
} catch (Exception e) {
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project byzer-notebook by byzer-org.
the class EnvironmentPropertyProcessor method postProcessEnvironment.
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (!preInitializationStarted.compareAndSet(false, true)) {
return;
}
for (PropertySource propertySource : environment.getPropertySources()) {
if (propertySource instanceof OriginTrackedMapPropertySource) {
OriginTrackedMapPropertySource originPropertySource = (OriginTrackedMapPropertySource) propertySource;
Map<String, Object> source = originPropertySource.getSource();
source.forEach((k, v) -> {
if (v instanceof OriginTrackedValue) {
Object value = ((OriginTrackedValue) v).getValue();
if (value instanceof String) {
Origin origin = ((OriginTrackedValue) v).getOrigin();
String trimVal = ((String) value).trim();
try {
Class<?> aClass = Class.forName(SPRING_ORIGIN_VALUE_CLASS);
Constructor<?> constructor = aClass.getDeclaredConstructor(CharSequence.class, Origin.class);
constructor.setAccessible(true);
// TODO decrypt password
Object o = constructor.newInstance(trimVal, origin);
source.put(k, o);
} catch (Exception e) {
log.error("Java reflection error", e);
}
}
}
});
}
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project fizz-gateway-community by wehotel.
the class DedicatedLineServiceRegistration method onApplicationEvent.
@SneakyThrows
@Override
public void onApplicationEvent(DedicatedLineWebServerInitializedEvent event) {
ReactiveWebServerApplicationContext applicationContext = event.getApplicationContext();
ConfigurableEnvironment env = applicationContext.getEnvironment();
String prefix = SystemConfig.FIZZ_DEDICATED_LINE_CLIENT_PREFIX + ".service-registration";
boolean eureka = env.containsProperty((prefix + ".eureka.instance.appname"));
boolean nacos = env.containsProperty((prefix + ".nacos.discovery.server-addr"));
if (eureka || nacos) {
if (eureka) {
Properties eurekaProperties = new Properties();
boolean find = false;
for (PropertySource<?> propertySource : env.getPropertySources()) {
if (propertySource instanceof OriginTrackedMapPropertySource) {
OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource;
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
for (String propertyName : propertyNames) {
if (propertyName.length() > 55) {
int eurekaPos = propertyName.indexOf("eureka");
if (eurekaPos > -1) {
eurekaProperties.setProperty(propertyName.substring(eurekaPos), originTrackedMapPropertySource.getProperty(propertyName).toString());
find = true;
}
}
}
if (find) {
break;
}
}
}
if (!find) {
log.error("no eureka config");
return;
}
fizzServiceRegistration = FizzEurekaHelper.getServiceRegistration(applicationContext, eurekaProperties);
}
if (nacos) {
Properties nacosProperties = new Properties();
boolean find = false;
for (PropertySource<?> propertySource : env.getPropertySources()) {
if (propertySource instanceof OriginTrackedMapPropertySource) {
OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource;
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
for (String propertyName : propertyNames) {
if (propertyName.length() > 64) {
int naocsPos = propertyName.indexOf("nacos");
if (naocsPos > -1) {
nacosProperties.setProperty(propertyName.substring(naocsPos), originTrackedMapPropertySource.getProperty(propertyName).toString());
find = true;
}
}
}
if (find) {
break;
}
}
}
if (!find) {
log.error("no nacos config");
return;
}
fizzServiceRegistration = FizzNacosHelper.getServiceRegistration(applicationContext, nacosProperties);
}
fizzServiceRegistration.register();
}
}
Aggregations