use of org.springframework.core.env.Environment in project cas by apereo.
the class DefaultCasConfigurationPropertiesSourceLocator method loadSettingsByApplicationProfiles.
/**
* Property files processed in order of non-profiles first and then profiles, and profiles are first to last
* with properties in the last profile overriding properties in previous profiles or non-profiles.
*
* @param environment Spring environment
* @param config Location of config files
* @return Merged properties
*/
private PropertySource<?> loadSettingsByApplicationProfiles(final Environment environment, final File config) {
val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment);
val resources = scanForConfigurationResources(environment, config, profiles);
val composite = new CompositePropertySource("applicationProfilesCompositeProperties");
LOGGER.info("Configuration files found at [{}] are [{}] under profile(s) [{}]", config, resources, profiles);
resources.forEach(Unchecked.consumer(f -> {
LOGGER.debug("Loading configuration file [{}]", f);
val loader = configurationPropertiesLoaderFactory.getLoader(f, "applicationProfilesProperties-" + f.getFilename());
composite.addFirstPropertySource(loader.load());
}));
return composite;
}
use of org.springframework.core.env.Environment in project cas by apereo.
the class DefaultCasConfigurationPropertiesSourceLocator method loadEmbeddedYamlOverriddenProperties.
private PropertySource<?> loadEmbeddedYamlOverriddenProperties(final ResourceLoader resourceLoader, final Environment environment) {
val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment);
val yamlFiles = profiles.stream().map(profile -> String.format("classpath:/application-%s.yml", profile)).sorted().map(resourceLoader::getResource).collect(Collectors.toList());
yamlFiles.add(resourceLoader.getResource("classpath:/application.yml"));
LOGGER.debug("Loading embedded YAML configuration files [{}]", yamlFiles);
val composite = new CompositePropertySource("embeddedYamlOverriddenCompositeProperties");
yamlFiles.forEach(resource -> {
LOGGER.trace("Loading YAML properties from [{}]", resource);
val source = configurationPropertiesLoaderFactory.getLoader(resource, String.format("embeddedYamlOverriddenProperties-%s", resource.getFilename())).load();
composite.addPropertySource(source);
});
return composite;
}
use of org.springframework.core.env.Environment in project canal by alibaba.
the class CanalAdapterLoader method loadAdapter.
private void loadAdapter(OuterAdapterConfig config, List<OuterAdapter> canalOutConnectors) {
try {
OuterAdapter adapter;
adapter = loader.getExtension(config.getName(), StringUtils.trimToEmpty(config.getKey()));
ClassLoader cl = Thread.currentThread().getContextClassLoader();
// 替换ClassLoader
Thread.currentThread().setContextClassLoader(adapter.getClass().getClassLoader());
Environment env = (Environment) SpringContext.getBean(Environment.class);
Properties evnProperties = null;
if (env instanceof StandardEnvironment) {
evnProperties = new Properties();
for (PropertySource<?> propertySource : ((StandardEnvironment) env).getPropertySources()) {
if (propertySource instanceof EnumerablePropertySource) {
String[] names = ((EnumerablePropertySource<?>) propertySource).getPropertyNames();
for (String name : names) {
Object val = env.getProperty(name);
if (val != null) {
evnProperties.put(name, val);
}
}
}
}
}
adapter.init(config, evnProperties);
Thread.currentThread().setContextClassLoader(cl);
canalOutConnectors.add(adapter);
logger.info("Load canal adapter: {} succeed", config.getName());
} catch (Exception e) {
logger.error("Load canal adapter: {} failed", config.getName(), e);
}
}
use of org.springframework.core.env.Environment in project Gaffer by gchq.
the class SwaggerConfigTest method shouldPullTitleFromEnvironment.
@Test
public void shouldPullTitleFromEnvironment() {
// Given
final String title = "My Gaffer Graph";
SwaggerConfig swaggerConfig = new SwaggerConfig();
Environment env = mock(Environment.class);
when(env.getProperty(APP_TITLE, APP_TITLE_DEFAULT)).thenReturn(title);
// When
swaggerConfig.setEnvironment(env);
ApiInfo apiInfo = swaggerConfig.apiInfo();
// Then
assertEquals(title, apiInfo.getTitle());
}
use of org.springframework.core.env.Environment in project Gaffer by gchq.
the class SwaggerConfigTest method shouldPullDescriptionFromEnvironment.
@Test
public void shouldPullDescriptionFromEnvironment() {
// Given
final String description = "My Gaffer Graph";
SwaggerConfig swaggerConfig = new SwaggerConfig();
Environment env = mock(Environment.class);
when(env.getProperty(APP_DESCRIPTION, APP_DESCRIPTION_DEFAULT)).thenReturn(description);
// When
swaggerConfig.setEnvironment(env);
ApiInfo apiInfo = swaggerConfig.apiInfo();
// Then
assertEquals(description, apiInfo.getDescription());
}
Aggregations