Search in sources :

Example 96 with Environment

use of org.springframework.core.env.Environment in project herd by FINRAOS.

the class DaoSpringModuleConfig method databasePropertySourcesPlaceholderConfigurer.

/**
 * The database supplied property sources placeholder configurer that allows access to externalized properties from a database. This method also adds a new
 * property source that contains the database properties to the environment.
 *
 * @return the property sources placeholder configurer.
 */
@Bean
public static PropertySourcesPlaceholderConfigurer databasePropertySourcesPlaceholderConfigurer() {
    // Get the configurable environment and add a new property source to it that contains the database properties.
    // That way, the properties can be accessed via the environment or via an injected @Value annotation.
    // We are adding this property source last so other property sources (e.g. system properties, environment variables) can be used
    // to override the database properties.
    Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment();
    if (environment instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment;
        ReloadablePropertySource reloadablePropertySource = new ReloadablePropertySource(ReloadablePropertySource.class.getName(), ConfigurationConverter.getProperties(getPropertyDatabaseConfiguration()), getPropertyDatabaseConfiguration());
        configurableEnvironment.getPropertySources().addLast(reloadablePropertySource);
    }
    return new PropertySourcesPlaceholderConfigurer();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ReloadablePropertySource(org.finra.herd.dao.ReloadablePropertySource) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Environment(org.springframework.core.env.Environment) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 97 with Environment

use of org.springframework.core.env.Environment in project nakadi by zalando.

the class HashPartitionStrategyCrutchTest method whenPartitionCountIsWrongThenIllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void whenPartitionCountIsWrongThenIllegalArgumentException() {
    final Environment env = mock(Environment.class);
    when(env.getProperty("nakadi.hashPartitioning.overrideOrder.p3", List.class)).thenReturn(ImmutableList.of("1", "2", "0", "3"));
    new HashPartitionStrategyCrutch(env, 4);
}
Also used : Environment(org.springframework.core.env.Environment) Test(org.junit.Test)

Example 98 with Environment

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

the class InspectorApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(InspectorApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 99 with Environment

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

the class CasConfigurationPropertiesEnvironmentManager method getStandaloneProfileConfigurationDirectory.

/**
 * Gets standalone profile configuration directory.
 *
 * @param environment the environment
 * @return the standalone profile configuration directory
 */
public File getStandaloneProfileConfigurationDirectory(final Environment environment) {
    val values = new LinkedHashSet<>(RelaxedPropertyNames.forCamelCase(PROPERTY_CAS_STANDALONE_CONFIGURATION_DIRECTORY).getValues());
    values.add(PROPERTY_CAS_STANDALONE_CONFIGURATION_DIRECTORY);
    val file = values.stream().map(key -> environment.getProperty(key, File.class)).filter(Objects::nonNull).findFirst().orElse(null);
    if (file != null && file.exists()) {
        LOGGER.trace("Received standalone configuration directory [{}]", file);
        return file;
    }
    return Arrays.stream(DEFAULT_CAS_CONFIG_DIRECTORIES).filter(File::exists).findFirst().orElse(null);
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Arrays(java.util.Arrays) Getter(lombok.Getter) Environment(org.springframework.core.env.Environment) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) ConfigurationPropertiesBindingPostProcessor(org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor) ApplicationContext(org.springframework.context.ApplicationContext) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames) File(java.io.File) LinkedHashSet(java.util.LinkedHashSet) Objects(java.util.Objects) File(java.io.File)

Example 100 with Environment

use of org.springframework.core.env.Environment in project dubbo by alibaba.

the class DubboBeanDefinitionParser method resolveAttribute.

private static String resolveAttribute(Element element, String attributeName, ParserContext parserContext) {
    String attributeValue = element.getAttribute(attributeName);
    Environment environment = parserContext.getReaderContext().getEnvironment();
    return environment.resolvePlaceholders(attributeValue);
}
Also used : Environment(org.springframework.core.env.Environment)

Aggregations

Environment (org.springframework.core.env.Environment)161 Test (org.junit.jupiter.api.Test)68 StandardEnvironment (org.springframework.core.env.StandardEnvironment)30 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)26 MockEnvironment (org.springframework.mock.env.MockEnvironment)24 SpringApplication (org.springframework.boot.SpringApplication)21 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)19 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)19 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)19 HashMap (java.util.HashMap)13 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)11 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)7 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)7 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)7 Map (java.util.Map)7 Predicate (java.util.function.Predicate)7