Search in sources :

Example 6 with Environment

use of org.springframework.core.env.Environment in project camel by apache.

the class CamelCloudServiceCallConfigurationTest method doTest.

@Test
public void doTest() throws Exception {
    Environment env = ctx.getEnvironment();
    assertFalse(env.getProperty("camel.cloud.enabled", Boolean.class));
    assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", Boolean.class));
    assertFalse(env.getProperty("camel.cloud.service-filter.enabled", Boolean.class));
    assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", Boolean.class));
    assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", Boolean.class));
    assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty());
    assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty());
    assertTrue(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
    assertTrue(ctx.getBeansOfType(LoadBalancer.class).isEmpty());
}
Also used : Environment(org.springframework.core.env.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Environment

use of org.springframework.core.env.Environment in project spring-boot-starter-dubbo by teaey.

the class DubboConfigurationApplicationContextInitializer method initialize.

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Environment env = applicationContext.getEnvironment();
    String scan = env.getProperty("spring.dubbo.scan");
    if (scan != null) {
        AnnotationBean scanner = BeanUtils.instantiate(AnnotationBean.class);
        scanner.setPackage(scan);
        scanner.setApplicationContext(applicationContext);
        applicationContext.addBeanFactoryPostProcessor(scanner);
        applicationContext.getBeanFactory().addBeanPostProcessor(scanner);
        applicationContext.getBeanFactory().registerSingleton("annotationBean", scanner);
    }
}
Also used : AnnotationBean(com.alibaba.dubbo.config.spring.AnnotationBean) Environment(org.springframework.core.env.Environment)

Example 8 with Environment

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

the class CasCoreBootstrapStandaloneConfiguration method loadSettingsFromConfigurationSources.

private void loadSettingsFromConfigurationSources(final Environment environment, final Properties props, final File config) {
    final List<String> profiles = new ArrayList<>();
    profiles.add(configurationPropertiesEnvironmentManager().getApplicationName());
    profiles.addAll(Arrays.stream(environment.getActiveProfiles()).collect(Collectors.toList()));
    final String propertyNames = profiles.stream().collect(Collectors.joining("|"));
    final String regex = String.format("(%s|application)\\.(yml|properties)", propertyNames);
    LOGGER.debug("Looking for configuration files at [{}] that match the pattern [{}]", config, regex);
    final Collection<File> configFiles = FileUtils.listFiles(config, new RegexFileFilter(regex, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE).stream().sorted(Comparator.comparing(File::getName)).collect(Collectors.toList());
    LOGGER.info("Configuration files found at [{}] are [{}]", config, configFiles);
    configFiles.forEach(Unchecked.consumer(f -> {
        LOGGER.debug("Loading configuration file [{}]", f);
        if (f.getName().toLowerCase().endsWith("yml")) {
            final Map pp = loadYamlProperties(new FileSystemResource(f));
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), f);
            props.putAll(pp);
        } else {
            final Properties pp = new Properties();
            pp.load(new FileReader(f));
            LOGGER.debug("Found settings [{}] in file [{}]", pp.keySet(), f);
            props.putAll(pp);
        }
    }));
}
Also used : Arrays(java.util.Arrays) IOCase(org.apache.commons.io.IOCase) PropertySource(org.springframework.core.env.PropertySource) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) Map(java.util.Map) CasConfigurationPropertiesEnvironmentManager(org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) Resource(org.springframework.core.io.Resource) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Properties(java.util.Properties) Collection(java.util.Collection) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileUtils(org.apache.commons.io.FileUtils) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) File(java.io.File) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Environment(org.springframework.core.env.Environment) Bean(org.springframework.context.annotation.Bean) FileReader(java.io.FileReader) Comparator(java.util.Comparator) YamlProcessor(org.springframework.beans.factory.config.YamlProcessor) PropertySourceLocator(org.springframework.cloud.bootstrap.config.PropertySourceLocator) ArrayList(java.util.ArrayList) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) FileReader(java.io.FileReader) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map)

Example 9 with Environment

use of org.springframework.core.env.Environment in project camel by apache.

the class CamelTestConfiguration method setApplicationContext.

/**
     * Build the URI of the CM Component based on Environmental properties
     */
@Override
public final void setApplicationContext(final ApplicationContext applicationContext) {
    super.setApplicationContext(applicationContext);
    final Environment env = applicationContext.getEnvironment();
    final String host = env.getRequiredProperty("cm.url");
    final String productTokenString = env.getRequiredProperty("cm.product-token");
    final String sender = env.getRequiredProperty("cm.default-sender");
    final StringBuffer cmUri = new StringBuffer("cm-sms:" + host).append("?productToken=").append(productTokenString);
    if (sender != null && !sender.isEmpty()) {
        cmUri.append("&defaultFrom=").append(sender);
    }
    // Defaults to false
    final Boolean testConnectionOnStartup = Boolean.parseBoolean(env.getProperty("cm.testConnectionOnStartup", "false"));
    if (testConnectionOnStartup) {
        cmUri.append("&testConnectionOnStartup=").append(testConnectionOnStartup.toString());
    }
    // Defaults to 8
    final Integer defaultMaxNumberOfParts = Integer.parseInt(env.getProperty("defaultMaxNumberOfParts", "8"));
    cmUri.append("&defaultMaxNumberOfParts=").append(defaultMaxNumberOfParts.toString());
    uri = cmUri.toString();
}
Also used : Environment(org.springframework.core.env.Environment)

Example 10 with Environment

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

the class SpringBootJoranConfigurator method addInstanceRules.

@Override
public void addInstanceRules(RuleStore rs) {
    super.addInstanceRules(rs);
    Environment environment = this.initializationContext.getEnvironment();
    rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment));
    rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(this.initializationContext.getEnvironment()));
    rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction());
}
Also used : NOPAction(ch.qos.logback.core.joran.action.NOPAction) Environment(org.springframework.core.env.Environment) ElementSelector(ch.qos.logback.core.joran.spi.ElementSelector)

Aggregations

Environment (org.springframework.core.env.Environment)14 Test (org.junit.Test)5 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)3 MutablePropertySources (org.springframework.core.env.MutablePropertySources)3 MockEnvironment (org.springframework.mock.env.MockEnvironment)3 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)2 NOPAction (ch.qos.logback.core.joran.action.NOPAction)1 ElementSelector (ch.qos.logback.core.joran.spi.ElementSelector)1 AnnotationBean (com.alibaba.dubbo.config.spring.AnnotationBean)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1