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

<T> T getProperty(String key, Class<T> targetType, T 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.joinfaces.annotations.JsfCdiToSpringAutoConfiguration.java

/**
 * BeanFactoryPostProcessor to enable jsf cdi annotations in spring.
 * @param environment environment to load de property to set the order
 * @return beanFactoryPostProcessor to enable jsf-cdi annotations
 *///w w w.  j  a v a  2s. c  o  m
@Bean
public static JsfCdiToSpringBeanFactoryPostProcessor jsfCdiToSpringBeanFactoryPostProcessor(
        Environment environment) {
    JsfCdiToSpringBeanFactoryPostProcessor bfpp = new JsfCdiToSpringBeanFactoryPostProcessor();
    bfpp.setOrder(
            environment.getProperty(JSF_CDI_CONFIGURATION_ORDER, Integer.class, Ordered.LOWEST_PRECEDENCE));
    return bfpp;
}

From source file:org.dimitrovchi.conf.service.ServiceParameterUtils.java

public static <P> P parameters(final String prefix, final Environment environment) {
    final AnnotationParameters aParameters = annotationParameters();
    return (P) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
            aParameters.annotations.toArray(new Class[aParameters.annotations.size()]),
            new InvocationHandler() {
                @Override//from   w w  w  .  jav  a2s  . co m
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if ("toString".equals(method.getName())) {
                        return reflectToString(prefix, proxy);
                    }
                    return environment.getProperty(prefix + "." + method.getName(),
                            (Class) method.getReturnType(), method.getDefaultValue());
                }
            });
}

From source file:org.cloudfoundry.identity.uaa.login.TileInfo.java

@Autowired
public TileInfo(Environment environment) {
    tiles = environment.getProperty("tiles", ArrayList.class, new ArrayList<LinkedHashMap<String, String>>());
}

From source file:se.crisp.codekvast.support.web.config.WebServerConfig.java

@Bean
public EmbeddedServletContainerFactory servletContainer(Environment environment) {
    Integer serverPort = environment.getProperty("server.port", Integer.class, 8080);
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    File keystore = new File(KEYSTORE_PATH);
    if (keystore.canRead() && serverPort != 0) {
        // Don't configure an SSL port during tests.
        tomcat.addAdditionalTomcatConnectors(createSslConnector(keystore, computeSslPort(serverPort)));
    }/*from w  w  w  .j av  a  2 s  . co m*/
    return tomcat;
}

From source file:org.ventiv.webjars.requirejs.servlet.RequireJsConfigServlet.java

/**
 * Used when created explicitly within a Spring Boot context
 *
 * @param env//www .ja va2 s  . co m
 */
public RequireJsConfigServlet(Environment env) {
    webJarRootUrl = env.getProperty("webjars.requirejs.config.rootUrl", String.class, webJarRootUrl);
    prettyPrint = env.getProperty("webjars.requirejs.config.prettyPrint", Boolean.class, prettyPrint);

    requireJsConfigBuilder = new RequireJsConfigBuilder(webJarRootUrl, env);
}

From source file:org.jrecruiter.common.ApiKeysHolder.java

@Autowired
public ApiKeysHolder(Environment environment) {

    this.twitterEnabled = environment.getProperty("twitter.enabled", Boolean.class, false);
    this.twitterConsumerKey = environment.getProperty("twitter.oauth.consumerKey", String.class, "");
    this.twitterConsumerSecret = environment.getProperty("twitter.oauth.consumerSecret", String.class, "");
    this.twitterAccessToken = environment.getProperty("twitter.oauth.accessToken", String.class, "");
    this.twitterAccessTokenSecret = environment.getProperty("twitter.oauth.accessTokenSecret", String.class,
            "");/*  w ww .ja  v a2 s  . c om*/

    this.bitlyEnabled = environment.getProperty("bitly.enabled", boolean.class, false);
    this.bitlyUsername = environment.getProperty("bitly.username", String.class, "");
    this.bitlyPassword = environment.getProperty("bitly.password", String.class, "");

    this.reCaptchaEnabled = environment.getProperty("recaptcha.enabled", boolean.class, false);
    this.reCaptchaPublicKey = environment.getProperty("recaptcha.publicKey", String.class, "");
    this.reCaptchaPrivateKey = environment.getProperty("recaptcha.privateKey", String.class, "");

}

From source file:org.vaadin.spring.i18n.MessageProviderCacheCleanupExecutor.java

/**
 * Creates a new {@code MessageProviderCacheCleanupExecutor} and starts up the cleanup thread if cache cleanup
 * has been enabled./*www .  j a v a 2s .c o m*/
 */
public MessageProviderCacheCleanupExecutor(final Environment environment,
        final CompositeMessageSource compositeMessageSource) {
    cleanupInterval = environment.getProperty(ENV_PROP_MESSAGE_PROVIDER_CACHE_CLEANUP_INTERVAL_SECONDS,
            Integer.class, 0);
    if (cleanupInterval > 0) {
        if (compositeMessageSource.isMessageFormatCacheEnabled()) {
            LOGGER.warn(
                    "The message format cache is enabled so message provider cache cleanup will not have any effect, disabling");
        } else {
            LOGGER.info("Cleaning up the message provider caches every {} second(s)", cleanupInterval);
            executorService = Executors.newSingleThreadScheduledExecutor();
            cleanupJob = executorService.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    LOGGER.debug("Cleaning up message provider caches");
                    compositeMessageSource.clearMessageProviderCaches();
                }
            }, cleanupInterval, cleanupInterval, TimeUnit.SECONDS);
        }
    } else {
        LOGGER.info("Message provider cache cleanup is disabled");
    }
}

From source file:at.ac.univie.isc.asio.nest.NestBluePrint.java

@Bean(destroyMethod = "close")
public JenaEngine jenaEngine(final Dataset dataset, final D2rqConfigModel d2rq, final Jdbc jdbc,
        final Timeout timeout, final Environment env) {
    final Integer poolSize = env.getProperty("asio.d2rq.pool-size", Integer.class, 1);
    final JenaFactory factory = PooledD2rqFactory.using(d2rq, jdbc, timeout, poolSize);
    return JenaEngine.using(factory, dataset.isFederationEnabled());
}

From source file:org.excalibur.service.deployment.server.ApplicationServer.java

protected void registerThisInstanceServices(final Class<?> serviceClass, final Environment environment,
        ApplicationConfig application) throws Exception {
    final String servicePath = serviceClass.getAnnotation(Path.class).value();

    ServiceInstance<ServiceDetails> instance = ServiceInstance.<ServiceDetails>builder()
            .name(thisInstance.getName() + servicePath).payload(new ServiceDetails())
            .port(environment.getProperty("org.excalibur.server.port", Integer.class, 8080))
            .uriSpec(application.getUriSpec(servicePath.substring(1))).build();

    services.add(instance);//from   w  w  w .ja  v a 2 s .c  om

    this.serviceDiscovery.registerService(instance);
}

From source file:org.finra.herd.core.helper.ConfigurationHelper.java

/**
 * Wrapper for {@link Environment#getProperty(String, Class, Object)} using the given {@link ConfigurationValue} as the key and default value. Optionally,
 * uses the configured default value if the property is not found in the environment. The configured default value must be of the same class, or must be a
 * sub-class of the given targetType./*from   w  w w  .j a va 2 s  .  com*/
 *
 * @param <T> The return type
 * @param configurationValue The {@link ConfigurationValue} with property key and default value.
 * @param targetType The returned object's type
 * @param environment The {@link Environment} containing the property
 *
 * @return The property value
 */
public static <T> T getProperty(ConfigurationValue configurationValue, Class<T> targetType,
        Environment environment) {
    /*
     * Parameter validation
     */
    if (configurationValue == null) {
        throw new IllegalStateException("configurationValue is required");
    }

    if (targetType == null) {
        throw new IllegalStateException("targetType is required");
    }

    String key = configurationValue.getKey();
    Object genericDefaultValue = configurationValue.getDefaultValue();

    /*
     * Assert that the targetType is of the correct type.
     */
    if (genericDefaultValue != null && !targetType.isAssignableFrom(genericDefaultValue.getClass())) {
        throw new IllegalStateException("targetType \"" + targetType
                + "\" is not assignable from the default value of type \"" + genericDefaultValue.getClass()
                + "\" for configuration value \"" + configurationValue + "\".");
    }

    @SuppressWarnings("unchecked")
    T defaultValue = (T) genericDefaultValue;

    T value = defaultValue;
    try {
        value = environment.getProperty(key, targetType, defaultValue);
    } catch (ConversionFailedException conversionFailedException) {
        /*
         * If the environment value is not convertible into the targetType, catch it and log a warning.
         * Return the default value.
         */
        LOGGER.warn(
                "Error converting environment property with key '" + key + "' and value '"
                        + environment.getProperty(key) + "' into a '" + targetType + "'.",
                conversionFailedException);
    }
    return value;
}