Search in sources :

Example 16 with PropertiesPropertySource

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);
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Properties(java.util.Properties) File(java.io.File)

Example 17 with PropertiesPropertySource

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);
        }
    }
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Example 18 with PropertiesPropertySource

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;
}
Also used : PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues) PropertyValues(org.springframework.beans.PropertyValues) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertySources(org.springframework.core.env.MutablePropertySources) PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues)

Example 19 with PropertiesPropertySource

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/");
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) Properties(java.util.Properties) Before(org.junit.Before)

Example 20 with PropertiesPropertySource

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;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Environment(org.springframework.core.env.Environment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) IOException(java.io.IOException)

Aggregations

PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)21 Properties (java.util.Properties)18 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 File (java.io.File)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Reader (java.io.Reader)2 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Resource (org.springframework.core.io.Resource)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 FileInputStream (java.io.FileInputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1