use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class AutoConfigurationImportSelector method getExcludeAutoConfigurationsProperty.
/**
* Returns the auto-configurations excluded by the
* {@code spring.autoconfigure.exclude} property.
* @return excluded auto-configurations
* @since 2.3.2
*/
protected List<String> getExcludeAutoConfigurationsProperty() {
Environment environment = getEnvironment();
if (environment == null) {
return Collections.emptyList();
}
if (environment instanceof ConfigurableEnvironment) {
Binder binder = Binder.get(environment);
return binder.bind(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class).map(Arrays::asList).orElse(Collections.emptyList());
}
String[] excludes = environment.getProperty(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class);
return (excludes != null) ? Arrays.asList(excludes) : Collections.emptyList();
}
use of org.springframework.core.env.Environment in project midpoint by Evolveum.
the class MidPointApplication method initializeSchrodinger.
private void initializeSchrodinger() {
if (applicationContext == null) {
return;
}
Environment environment = applicationContext.getEnvironment();
if (environment == null) {
return;
}
String value = environment.getProperty(MidpointConfiguration.MIDPOINT_SCHRODINGER_PROPERTY);
boolean enabled = Boolean.parseBoolean(value);
if (enabled) {
LOGGER.info("Schrodinger plugin enabled");
getComponentInitializationListeners().add(new SchrodingerComponentInitListener());
}
}
use of org.springframework.core.env.Environment in project dubbo by alibaba.
the class DubboConfigBeanDefinitionConflictApplicationListener method resolveUniqueApplicationConfigBean.
/**
* Resolve the unique {@link ApplicationConfig} Bean
* @param registry {@link BeanDefinitionRegistry} instance
* @param beanFactory {@link ConfigurableListableBeanFactory} instance
* @see EnableDubboConfig
*/
private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ListableBeanFactory beanFactory) {
String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length < 2) {
// If the number of ApplicationConfig beans is less than two, return immediately.
return;
}
Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
// Remove ApplicationConfig Beans that are configured by "dubbo.application.*"
Stream.of(beansNames).filter(beansName -> isConfiguredApplicationConfigBeanName(environment, beansName)).forEach(registry::removeBeanDefinition);
beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length > 1) {
throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames).map(registry::getBeanDefinition).collect(Collectors.toList())));
}
}
use of org.springframework.core.env.Environment in project cas by apereo.
the class CasConfigurationPropertiesEnvironmentManager method getStandaloneProfileConfigurationFile.
/**
* Gets standalone profile configuration file.
*
* @param environment the environment
* @return the standalone profile configuration file
*/
public File getStandaloneProfileConfigurationFile(final Environment environment) {
val values = new LinkedHashSet<>(RelaxedPropertyNames.forCamelCase(PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE).getValues());
values.add(PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE);
return values.stream().map(key -> environment.getProperty(key, File.class)).filter(Objects::nonNull).findFirst().orElse(null);
}
use of org.springframework.core.env.Environment in project cas by apereo.
the class DefaultCasConfigurationPropertiesSourceLocator method getAllPossibleExternalConfigDirFilenames.
/**
* Make a list of files that will be processed in order where the last one processed wins.
* Profiles are added after base property names like {@code application.properties}, {@code cas.properties},
* {@code CAS.properties} so that the profiles will override the base properties.
* <p>
* Profiles are processed in order so that the last profile list (e.g. in {@code spring.active.profiles}) will override the
* the first profile.
* <p>
* Where multiple filenames with same base name and different extensions exist, the priority is yaml, yml, properties.
*/
private List<File> getAllPossibleExternalConfigDirFilenames(final Environment environment, final File configDirectory, final List<String> profiles) {
val applicationName = casConfigurationPropertiesEnvironmentManager.getApplicationName(environment);
val configName = casConfigurationPropertiesEnvironmentManager.getConfigurationName(environment);
val appNameLowerCase = applicationName.toLowerCase();
val appConfigNames = CollectionUtils.wrapList("application", appNameLowerCase, applicationName, configName);
val fileNames = appConfigNames.stream().distinct().flatMap(appName -> EXTENSIONS.stream().map(ext -> new File(configDirectory, String.format("%s.%s", appName, ext)))).filter(File::exists).collect(Collectors.toList());
fileNames.addAll(profiles.stream().flatMap(profile -> EXTENSIONS.stream().flatMap(ext -> PROFILE_PATTERNS.stream().map(pattern -> new File(configDirectory, String.format(pattern, profile, ext))))).filter(File::exists).collect(Collectors.toList()));
fileNames.addAll(profiles.stream().map(profile -> EXTENSIONS.stream().map(ext -> appConfigNames.stream().map(appName -> new File(configDirectory, String.format("%s-%s.%s", appName, profile, ext))).filter(File::exists).collect(Collectors.toList())).flatMap(List::stream).collect(Collectors.toList())).flatMap(List::stream).collect(Collectors.toList()));
val groovyFile = new File(configDirectory, appNameLowerCase.concat(".groovy"));
FunctionUtils.doIf(groovyFile.exists(), o -> fileNames.add(groovyFile)).accept(groovyFile);
return fileNames;
}
Aggregations