use of org.springframework.core.env.PropertiesPropertySource in project cas by apereo.
the class CasCoreBootstrapStandaloneConfiguration method locate.
@Override
public PropertySource<?> locate(final Environment environment) {
final Properties props = new Properties();
loadEmbeddedYamlOverriddenProperties(props);
final File config = configurationPropertiesEnvironmentManager().getStandaloneProfileConfigurationDirectory();
LOGGER.debug("Located CAS standalone configuration directory at [{}]", config);
if (config.isDirectory() && config.exists()) {
loadSettingsFromConfigurationSources(environment, props, config);
} else {
LOGGER.warn("Configuration directory [{}] is not a directory or cannot be found at the specific path", config);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Located setting(s) [{}] from [{}]", props.keySet(), config);
} else {
LOGGER.info("Found and loaded [{}] setting(s) from [{}]", props.size(), config);
}
return new PropertiesPropertySource("standaloneCasConfigService", props);
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.
the class DevToolsHomePropertiesPostProcessor method postProcessEnvironment.
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
File home = getHomeFolder();
File propertyFile = (home == null ? null : new File(home, FILE_NAME));
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
FileSystemResource resource = new FileSystemResource(propertyFile);
Properties properties;
try {
properties = PropertiesLoaderUtils.loadProperties(resource);
environment.getPropertySources().addFirst(new PropertiesPropertySource("devtools-local", properties));
} catch (IOException ex) {
throw new IllegalStateException("Unable to load " + FILE_NAME, ex);
}
}
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.
the class SpringProfileDocumentMatcher method extractSpringProfiles.
protected List<String> extractSpringProfiles(Properties properties) {
SpringProperties springProperties = new SpringProperties();
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("profiles", properties));
PropertyValues propertyValues = new PropertySourcesPropertyValues(propertySources);
new RelaxedDataBinder(springProperties, "spring").bind(propertyValues);
List<String> profiles = springProperties.getProfiles();
return profiles;
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-framework by spring-projects.
the class CrossOriginTests method setup.
@Before
public void setup() {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
Properties props = new Properties();
props.setProperty("myOrigin", "http://example.com");
wac.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("ps", props));
wac.registerSingleton("ppc", PropertySourcesPlaceholderConfigurer.class);
wac.refresh();
this.handlerMapping.setRemoveSemicolonContent(false);
wac.getAutowireCapableBeanFactory().initializeBean(this.handlerMapping, "hm");
this.request.setMethod("GET");
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain.com/");
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurer method postProcessBeanFactory.
/**
* {@inheritDoc}
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* against this configurer's set of {@link PropertySources}, which includes:
* <ul>
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
* environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
* <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
* {@linkplain #setLocations have} {@linkplain #setProperties been}
* {@linkplain #setPropertiesArray specified}
* <li>any property sources set by calling {@link #setPropertySources}
* </ul>
* <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
* ignored</strong>. This method is designed to give the user fine-grained control over property
* sources, and once set, the configurer makes no assumptions about adding additional sources.
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.propertySources == null) {
this.propertySources = new MutablePropertySources();
if (this.environment != null) {
this.propertySources.addLast(new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
@Override
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
}
try {
PropertySource<?> localPropertySource = new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
if (this.localOverride) {
this.propertySources.addFirst(localPropertySource);
} else {
this.propertySources.addLast(localPropertySource);
}
} catch (IOException ex) {
throw new BeanInitializationException("Could not load properties", ex);
}
}
processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
this.appliedPropertySources = this.propertySources;
}
Aggregations