Search in sources :

Example 1 with PropertySources

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

the class SpringBootTestContextBootstrapper method getConfiguredWebApplicationType.

private WebApplicationType getConfiguredWebApplicationType(MergedContextConfiguration configuration) {
    PropertySources sources = convertToPropertySources(configuration.getPropertySourceProperties());
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(new PropertySourcesPropertyResolver(sources), "spring.main.");
    String property = resolver.getProperty("web-application-type");
    return (property != null ? WebApplicationType.valueOf(property.toUpperCase()) : null);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 2 with PropertySources

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

the class SpringBootContextLoader method hasCustomServerPort.

private boolean hasCustomServerPort(List<String> properties) {
    PropertySources sources = convertToPropertySources(properties);
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(new PropertySourcesPropertyResolver(sources), "server.");
    return resolver.containsProperty("port");
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 3 with PropertySources

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

the class PropertySourcesDeducerTests method getPropertySourcesWhenHasNoPropertySourcesPlaceholderConfigurerReturnsEnvironmentSources.

@Test
void getPropertySourcesWhenHasNoPropertySourcesPlaceholderConfigurerReturnsEnvironmentSources() {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
    ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
    environment.getPropertySources().addFirst(new TestPropertySource());
    PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
    PropertySources propertySources = deducer.getPropertySources();
    assertThat(propertySources.get("test")).isInstanceOf(TestPropertySource.class);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with PropertySources

use of org.springframework.core.env.PropertySources in project kylo by Teradata.

the class Inspections method inspect.

public Object inspect(String path, String inspectionsPath, String isDevMode, String projectVersion) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    Configuration config = new DefaultConfiguration(path, inspectionsPath, isDevMode, projectVersion);
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
    ppc.setLocation(new FileSystemResource(config.getServicesConfigLocation()));
    ppc.setIgnoreUnresolvablePlaceholders(true);
    ppc.setIgnoreResourceNotFound(false);
    ppc.postProcessBeanFactory(ctx.getBeanFactory());
    ppc.setEnvironment(ctx.getEnvironment());
    PropertySources sources = ppc.getAppliedPropertySources();
    sources.forEach(source -> ctx.getEnvironment().getPropertySources().addLast(source));
    ctx.scan("com.thinkbiganalytics.install.inspector.inspection", "com.thinkbiganalytics.hive.config", "com.thinkbiganalytics.spring");
    ctx.refresh();
    InspectionService service = ctx.getBean(InspectionService.class);
    return service.inspect(config);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertySources(org.springframework.core.env.PropertySources) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 5 with PropertySources

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

the class PropertySourcesDeducerTests method getPropertySourcesWhenHasMultiplePropertySourcesPlaceholderConfigurerReturnsEnvironmentSources.

@Test
void getPropertySourcesWhenHasMultiplePropertySourcesPlaceholderConfigurerReturnsEnvironmentSources() {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MultiplePropertySourcesPlaceholderConfigurerConfiguration.class);
    ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
    environment.getPropertySources().addFirst(new TestPropertySource());
    PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
    PropertySources propertySources = deducer.getPropertySources();
    assertThat(propertySources.get("test")).isInstanceOf(TestPropertySource.class);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

PropertySources (org.springframework.core.env.PropertySources)6 MutablePropertySources (org.springframework.core.env.MutablePropertySources)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 Test (org.junit.jupiter.api.Test)3 ApplicationContext (org.springframework.context.ApplicationContext)3 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)2 PropertySourcesPlaceholderConfigurer (org.springframework.context.support.PropertySourcesPlaceholderConfigurer)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1