Example usage for org.springframework.core.env Environment getProperty

List of usage examples for org.springframework.core.env Environment getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env Environment getProperty.

Prototype

String getProperty(String key, String defaultValue);

Source Link

Document

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Usage

From source file:org.aksw.simba.tapioca.server.Config.java

public static @Bean WorkerBasedLabelRetrievingDocumentSupplierDecorator createCachingLabelRetriever(
        Environment env) {
    File labelFiles[] = {}; // TODO add label files
    String cacheFileNames[] = env.getProperty(LABEL_CACHING_FILES_PROPERTY_KEY, (new String[0]).getClass());
    File chacheFiles[] = new File[cacheFileNames.length];
    for (int i = 0; i < chacheFiles.length; ++i) {
        chacheFiles[i] = new File(cacheFileNames[i]);
    }//  w  w  w. j ava 2s  . c o m
    return new WorkerBasedLabelRetrievingDocumentSupplierDecorator(null, chacheFiles, labelFiles);
}

From source file:eu.openanalytics.WebSecurityConfig.java

private static boolean hasAuth(Environment env) {
    String auth = env.getProperty("shiny.proxy.authentication", "").toLowerCase();
    return (!auth.isEmpty() && !auth.equals("none"));
}

From source file:lab.mage.spring.cassandra.connector.core.OptionProvider.java

private static void lazyOptionInit(final Environment env) {
    OptionProvider.CACHED_OPTIONS.put(CassandraConnectorConstants.CONSISTENCY_LEVEL_DELETE_PROP,
            Mapper.Option.consistencyLevel(ConsistencyLevel
                    .valueOf(env.getProperty(CassandraConnectorConstants.CONSISTENCY_LEVEL_DELETE_PROP,
                            CassandraConnectorConstants.CONSISTENCY_LEVEL_PROP_DEFAULT))));

    OptionProvider.CACHED_OPTIONS.put(CassandraConnectorConstants.CONSISTENCY_LEVEL_READ_PROP,
            Mapper.Option.consistencyLevel(ConsistencyLevel
                    .valueOf(env.getProperty(CassandraConnectorConstants.CONSISTENCY_LEVEL_READ_PROP,
                            CassandraConnectorConstants.CONSISTENCY_LEVEL_PROP_DEFAULT))));

    OptionProvider.CACHED_OPTIONS.put(CassandraConnectorConstants.CONSISTENCY_LEVEL_WRITE_PROP,
            Mapper.Option.consistencyLevel(ConsistencyLevel
                    .valueOf(env.getProperty(CassandraConnectorConstants.CONSISTENCY_LEVEL_WRITE_PROP,
                            CassandraConnectorConstants.CONSISTENCY_LEVEL_PROP_DEFAULT))));

}

From source file:io.fabric8.spring.cloud.kubernetes.config.SecretsPropertySource.java

private static String getApplicationName(Environment env, SecretsConfigProperties config) {
    String name = config.getName();
    if (StringUtils.isEmpty(name)) {
        LOGGER.debug("Secret name has not been set, taking it from property/env {} (default={})",
                Constants.SPRING_APPLICATION_NAME, Constants.FALLBACK_APPLICATION_NAME);

        name = env.getProperty(Constants.SPRING_APPLICATION_NAME, Constants.FALLBACK_APPLICATION_NAME);
    }/*from  ww w. j a  va  2 s .c  o m*/

    return name;
}

From source file:org.vaadin.spring.samples.mvp.security.config.InMemoryAuthenticationBuilder.java

void build(Environment env, AuthenticationManagerBuilder auth) throws Exception {
    String username = env.getProperty("app.user.name", "admin");
    String password = env.getProperty("app.user.password", "admin");
    InMemoryUserDetailsManagerConfigurer<?> inmem = auth.inMemoryAuthentication();

    // remember to annotate service methods with @org.springframework.security.access.annotation.Secured
    inmem.withUser(username).password(password).authorities(FunctionalRole.ADMIN.getRoleName());

    // other "fake" accounts; for demonstration purposes
    inmem.withUser("user").password("user").authorities(FunctionalRole.PUBLIC.getRoleName());

}

From source file:com.payu.ratel.config.beans.InMemoryRegistryBeanProviderFactory.java

private String getRatelServiceAddress(final Environment env) {
    final String inMemoryServerAddress = env.getProperty(RegistryBeanProviderFactory.SERVICE_DISCOVERY_ADDRESS,
            DEFAULT_DISCOVERY_URL);
    return inMemoryServerAddress;
}

From source file:web.GeneratedBanner.java

private String generateBanner(Environment environment, Class<?> sourceClass) {
    String key = environment.getProperty("spring.application.name", sourceClass.getSimpleName());
    try {//from w w w.j av  a  2s  .c  o m
        return FigletFont.convertOneLine(key);
    } catch (IOException ex) {
        LoggerFactory.getLogger(getClass()).warn("Cannot generated banner", ex);
        return key;
    }
}

From source file:com.domingosuarez.boot.autoconfigure.jade4j.Jade4JTemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("de.neuland.jade4j.spring.template.SpringTemplateLoader", classLoader)) {
        String prefix = environment.getProperty("spring.jade4j.prefix", Jade4JAutoConfiguration.DEFAULT_PREFIX);
        String suffix = environment.getProperty("spring.jade4j.suffix", Jade4JAutoConfiguration.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }/*from  www. j a v a2s. co  m*/

    return false;
}

From source file:shiver.me.timbers.waiting.SpringPropertyGetterTest.java

@Test
public void Can_get_a_default_spring_property() {

    final String key = someString();

    final Environment environment = mock(Environment.class);

    final Object expected = new Object();

    // Given//w w  w .j  a v  a2s.c o  m
    given(context.getEnvironment()).willReturn(environment);
    given(environment.getProperty(key, expected.toString())).willReturn(expected.toString());

    // When
    final String actual = getter.get(key, expected);

    // Then
    assertThat(actual, equalTo(expected.toString()));
}