Search in sources :

Example 6 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.

the class BuildInfoContributor method toSimplePropertySource.

@Override
protected PropertySource<?> toSimplePropertySource() {
    Properties props = new Properties();
    copyIfSet(props, "group");
    copyIfSet(props, "artifact");
    copyIfSet(props, "name");
    copyIfSet(props, "version");
    copyIfSet(props, "time");
    return new PropertiesPropertySource("build", props);
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Properties(java.util.Properties) BuildProperties(org.springframework.boot.info.BuildProperties)

Example 7 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.

the class GitInfoContributor method toSimplePropertySource.

@Override
protected PropertySource<?> toSimplePropertySource() {
    Properties props = new Properties();
    copyIfSet(props, "branch");
    String commitId = getProperties().getShortCommitId();
    if (commitId != null) {
        props.put("commit.id", commitId);
    }
    copyIfSet(props, "commit.time");
    return new PropertiesPropertySource("git", props);
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) GitProperties(org.springframework.boot.info.GitProperties) Properties(java.util.Properties)

Example 8 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project spring-framework by spring-projects.

the class CrossOriginAnnotationIntegrationTests method initApplicationContext.

@Override
protected ApplicationContext initApplicationContext() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(WebConfig.class);
    Properties props = new Properties();
    props.setProperty("myOrigin", "http://site1.com");
    context.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("ps", props));
    context.register(PropertySourcesPlaceholderConfigurer.class);
    context.refresh();
    return context;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Properties(java.util.Properties)

Example 9 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project Activiti by Activiti.

the class CustomMybatisMapperConfigurationTest method context.

private AnnotationConfigApplicationContext context(Class<?>... clzz) throws IOException {
    AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
    annotationConfigApplicationContext.register(clzz);
    File springBootPropertiesFile = new File("src/test/resources/config/application.properties");
    Properties springBootProperties = new Properties();
    springBootProperties.load(new FileInputStream(springBootPropertiesFile));
    annotationConfigApplicationContext.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("testProperties", springBootProperties));
    annotationConfigApplicationContext.refresh();
    return annotationConfigApplicationContext;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 10 with PropertiesPropertySource

use of org.springframework.core.env.PropertiesPropertySource in project uPortal by Jasig.

the class PortalPropertySourcesPlaceholderConfigurer method postProcessBeanFactory.

/**
     * Override the postProcessing. The default PropertySourcesPlaceholderConfigurer does not inject
     * local properties into the Environment object. It builds a local list of properties files and
     * then uses a transient Resolver to resolve the @Value annotations. That means that you are
     * unable to get to "local" properties (eg. portal.properties) after bean post-processing has
     * completed unless you are going to re-parse those file. This is similar to what
     * PropertiesManager does, but it uses all the property files configured, not just
     * portal.properties.
     *
     * <p>If we upgrade to spring 4, there are better/more efficient solutions available. I'm not
     * aware of better solutions for spring 3.x.
     *
     * @param beanFactory the bean factory
     * @throws BeansException if an error occurs while loading properties or wiring up beans
     */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (propertyResolver == null) {
        try {
            MutablePropertySources sources = new MutablePropertySources();
            PropertySource<?> localPropertySource = new PropertiesPropertySource(EXTENDED_PROPERTIES_SOURCE, mergeProperties());
            sources.addLast(localPropertySource);
            propertyResolver = new PropertySourcesPropertyResolver(sources);
        } catch (IOException e) {
            throw new BeanInitializationException("Could not load properties", e);
        }
    }
    super.postProcessBeanFactory(beanFactory);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) IOException(java.io.IOException)

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