@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableEnvironment environment = (ConfigurableEnvironment) context .getEnvironment(); ResourceProperties properties = new ResourceProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources"); binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); Boolean match = properties.getChain().getEnabled(); if (match == null) { boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR, getClass().getClassLoader()); return new ConditionOutcome(webJarsLocatorPresent, "Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is " + (webJarsLocatorPresent ? "present" : "absent")); } return new ConditionOutcome(match, "Resource chain is " + (match ? "enabled" : "disabled")); }
private List<String> getExcludeAutoConfigurationsProperty() { if (getEnvironment() instanceof ConfigurableEnvironment) { Excludes excludes = new Excludes(); RelaxedDataBinder binder = new RelaxedDataBinder(excludes, "spring.autoconfigure."); binder.bind(new PropertySourcesPropertyValues( ((ConfigurableEnvironment) getEnvironment()).getPropertySources())); return excludes.getExclude(); } RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), "spring.autoconfigure."); String[] exclude = resolver.getProperty("exclude", String[].class); return (Arrays.asList(exclude == null ? new String[0] : exclude)); }
@Override public void setEnvironment(Environment environment) { this.environment = (ConfigurableEnvironment) environment; this.target = new HashMap<String, Object>(); new RelaxedDataBinder(this.target).bind( new PropertySourcesPropertyValues(this.environment.getPropertySources())); this.propertyResolver = new RelaxedPropertyResolver(environment); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableEnvironment environment = (ConfigurableEnvironment) context .getEnvironment(); ResourceProperties properties = new ResourceProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources"); binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); Boolean match = properties.getChain().getEnabled(); return new ConditionOutcome(match, "Resource chain is " + (match ? "enabled" : "disabled")); }
@Override public void initialize(ConfigurableApplicationContext applicationContext) { if (!isHasCloudConfigLocator(this.propertySourceLocators)) { logger.info("未启用Config Server管理配置"); return; } logger.info("检查Config Service配置资源"); ConfigurableEnvironment environment = applicationContext.getEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); logger.info("加载PropertySources源:" + propertySources.size() + "个"); CloudConfigSupportProperties configSupportProperties = new CloudConfigSupportProperties(); new RelaxedDataBinder(configSupportProperties, CloudConfigSupportProperties.CONFIG_PREFIX) .bind(new PropertySourcesPropertyValues(propertySources)); if (!configSupportProperties.isEnable()) { logger.warn("未启用配置备份功能,可使用{}.enable打开", CloudConfigSupportProperties.CONFIG_PREFIX); return; } if (isCloudConfigLoaded(propertySources)) { PropertySource cloudConfigSource = getLoadedCloudPropertySource(propertySources); logger.info("成功获取ConfigService配置资源"); //备份 Map<String, Object> backupPropertyMap = makeBackupPropertyMap(cloudConfigSource); doBackup(backupPropertyMap, configSupportProperties.getFile()); } else { logger.error("获取ConfigService配置资源失败"); Properties backupProperty = loadBackupProperty(configSupportProperties.getFile()); if (backupProperty != null) { HashMap backupSourceMap = new HashMap<>(backupProperty); PropertySource backupSource = new MapPropertySource("backupSource", backupSourceMap); propertySources.addFirst(backupSource); logger.warn("使用备份的配置启动:{}", configSupportProperties.getFile()); } } }
public RestifyApiClient client(RestifyableType type) { RestifyApiClient restifyApiClient = new RestifyApiClient(); RelaxedDataBinder dataBinder = new RelaxedDataBinder(restifyApiClient, "restify." + type.name()); ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment; dataBinder.bind(new PropertySourcesPropertyValues(configurableEnvironment.getPropertySources())); return restifyApiClient; }