Search in sources :

Example 11 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project cas by apereo.

the class CasPropertiesConfiguration method init.

/**
     * Init.
     */
@PostConstruct
public void init() {
    final Properties sysProps = System.getProperties();
    final Properties properties = new Properties();
    if (CasVersion.getVersion() != null) {
        properties.put("info.cas.version", CasVersion.getVersion());
    }
    properties.put("info.cas.date", CasVersion.getDateTime());
    properties.put("info.cas.java.home", sysProps.get("java.home"));
    properties.put("info.cas.java.vendor", sysProps.get("java.vendor"));
    properties.put("info.cas.java.version", sysProps.get("java.version"));
    final PropertiesPropertySource src = new PropertiesPropertySource(CasVersion.class.getName(), properties);
    this.environment.getPropertySources().addFirst(src);
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) CasVersion(org.apereo.cas.util.CasVersion) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Properties(java.util.Properties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) PostConstruct(javax.annotation.PostConstruct)

Example 12 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 13 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 14 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 15 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)

Aggregations

PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)16 Properties (java.util.Properties)13 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 File (java.io.File)3 IOException (java.io.IOException)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)2 FileInputStream (java.io.FileInputStream)1 PostConstruct (javax.annotation.PostConstruct)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 CasVersion (org.apereo.cas.util.CasVersion)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PropertyValues (org.springframework.beans.PropertyValues)1 PropertySourcesPropertyValues (org.springframework.boot.bind.PropertySourcesPropertyValues)1 RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)1 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)1 BuildProperties (org.springframework.boot.info.BuildProperties)1