Example usage for org.springframework.core.env PropertySource PropertySource

List of usage examples for org.springframework.core.env PropertySource PropertySource

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public PropertySource(String name) 

Source Link

Document

Create a new PropertySource with the given name and with a new Object instance as the underlying source.

Usage

From source file:natalia.dymnikova.configuration.ConfiguredEnvironment.java

@Override
protected void customizePropertySources(final MutablePropertySources propertySources) {
    propertySources.addLast(new PropertySource<Object>(CONFIGURED_PROPERTY_SOURCE) {
        @Override//from  www .j a  v  a  2  s .c o m
        public Object getProperty(final String name) {
            try {
                final com.typesafe.config.ConfigValue value = config.getValue(name);
                final ConfigValueType valueType = value.valueType();

                if (ConfigValueType.OBJECT == valueType || ConfigValueType.LIST == valueType) {
                    final Config config = ((ConfigObject) value).toConfig();
                    log.trace("Loaded configuration object {} = {}", name, config);
                    return config;
                } else {
                    log.trace("Loaded configuration value {} = {}", name, value);
                    return value.unwrapped();
                }
            } catch (final ConfigException e) {
                return null;
            }
        }
    });
}

From source file:org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration.java

/**
 * Add an alias for 'local.management.port' that actually resolves using
 * 'local.server.port'./*from   ww w. j a v  a  2 s . c o  m*/
 * @param environment the environment
 */
private void addLocalManagementPortPropertyAlias(final ConfigurableEnvironment environment) {
    environment.getPropertySources().addLast(new PropertySource<Object>("Management Server") {
        @Override
        public Object getProperty(String name) {
            if ("local.management.port".equals(name)) {
                return environment.getProperty("local.server.port");
            }
            return null;
        }
    });
}