Class PropertySourcesUtils

java.lang.Object
io.microsphere.spring.core.env.PropertySourcesUtils
All Implemented Interfaces:
io.microsphere.util.Utils

public abstract class PropertySourcesUtils extends Object implements io.microsphere.util.Utils
PropertySources Utilities
Since:
1.0.0
Author:
Mercy
See Also:
  • PropertySources
  • Field Details

    • DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME

      public static final String DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME
      The PropertySource name of Spring Boot default poperties
      See Also:
      • org.springframework.boot.DefaultPropertiesPropertySource#addOrMerge(Map, MutablePropertySources)
      • org.springframework.boot.DefaultPropertiesPropertySource#NAME
      • Constant Field Values
    • BOOTSTRAP_PROPERTY_SOURCE_NAME

      public static final String BOOTSTRAP_PROPERTY_SOURCE_NAME
      The PropertySource name of Spring Cloud Bootstrap context
      See Also:
      • org.springframework.cloud.bootstrap.BootstrapApplicationListener#BOOTSTRAP_PROPERTY_SOURCE_NAME
      • Constant Field Values
  • Method Details

    • getPropertySource

      public static <T extends org.springframework.core.env.PropertySource<?>> T getPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertySourceName, Class<T> propertySourceType)
    • getPropertySource

      public static <T extends org.springframework.core.env.PropertySource<?>> T getPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertySourceName, Class<T> propertySourceType, Supplier<T> propertySourceSupplierIfAbsent)
    • getMapPropertySource

      public static org.springframework.core.env.MapPropertySource getMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertySourceName)
    • getMapPropertySource

      public static org.springframework.core.env.MapPropertySource getMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertySourceName, boolean created)
    • findConfiguredPropertySource

      public static org.springframework.core.env.PropertySource findConfiguredPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertyName)
    • findConfiguredPropertySource

      public static org.springframework.core.env.PropertySource findConfiguredPropertySource(Iterable<org.springframework.core.env.PropertySource<?>> propertySources, String propertyName)
    • findConfiguredPropertySourceName

      public static String findConfiguredPropertySourceName(org.springframework.core.env.ConfigurableEnvironment environment, String propertyName)
    • findConfiguredPropertySourceName

      public static String findConfiguredPropertySourceName(Iterable<org.springframework.core.env.PropertySource<?>> propertySources, String propertyName)
    • findPropertyNamesByPrefix

      public static Set<String> findPropertyNamesByPrefix(org.springframework.core.env.ConfigurableEnvironment environment, String propertyNamePrefix)
    • findPropertyNames

      public static Set<String> findPropertyNames(org.springframework.core.env.ConfigurableEnvironment environment, Predicate<String> propertyNameFilter)
    • getSubProperties

      public static Map<String,Object> getSubProperties(Iterable<org.springframework.core.env.PropertySource<?>> propertySources, String prefix)
      Get Sub Properties
      Parameters:
      propertySources - PropertySource Iterable
      prefix - the prefix of property name
      Returns:
      Map
      See Also:
    • getSubProperties

      public static Map<String,Object> getSubProperties(org.springframework.core.env.ConfigurableEnvironment environment, String prefix)
      Get Sub Properties
      Parameters:
      environment - ConfigurableEnvironment
      prefix - the prefix of property name
      Returns:
      Map
      See Also:
    • normalizePrefix

      public static String normalizePrefix(String prefix)
      Normalize the prefix
      Parameters:
      prefix - the prefix
      Returns:
      the prefix
    • getSubProperties

      public static Map<String,Object> getSubProperties(org.springframework.core.env.PropertySources propertySources, String prefix)
      Get prefixed Properties
      Parameters:
      propertySources - PropertySources
      prefix - the prefix of property name
      Returns:
      Map
      Since:
      1.0.0
      See Also:
    • getSubProperties

      public static Map<String,Object> getSubProperties(org.springframework.core.env.PropertySources propertySources, org.springframework.core.env.PropertyResolver propertyResolver, String prefix)
      Get prefixed Properties
      Parameters:
      propertySources - PropertySources
      propertyResolver - PropertyResolver to resolve the placeholder if present
      prefix - the prefix of property name
      Returns:
      Map
      Since:
      1.0.0
      See Also:
    • getPropertyNames

      @Nonnull public static String[] getPropertyNames(org.springframework.core.env.PropertySource propertySource)
      Get the property names as the array from the specified PropertySource instance.
      Parameters:
      propertySource - PropertySource instance
      Returns:
      non-null
      Since:
      1.0.0
    • getProperties

      @Nonnull public static Map<String,Object> getProperties(org.springframework.core.env.PropertySource propertySource)
      Get the Map as the properties from the specified PropertySource
      Parameters:
      propertySource - the specified PropertySource
      Returns:
      non-null read-only Map
    • addDefaultProperties

      public static void addDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, String key, Object value, Object... others)
    • getDefaultProperties

      public static Map<String,Object> getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment)
      Get the Map properties from the "default" PropertySource that is the lowest order one of the Spring PropertySources is created if absent
      Parameters:
      environment - ConfigurableEnvironment
      Returns:
      non-null mutable Map
      See Also:
    • getDefaultProperties

      public static Map<String,Object> getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, boolean createIfAbsent)
      Get the Map properties from the "default" PropertySource that is the lowest order one of the Spring PropertySources is created if specified.
      Parameters:
      environment - ConfigurableEnvironment
      createIfAbsent - true indicates the "default" PropertySource will be created if absent
      Returns:
      non-null mutable Map
      See Also:
    • getDefaultPropertiesPropertySource

      public static org.springframework.core.env.MapPropertySource getDefaultPropertiesPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)
      Get the "default" PropertySource that is the lowest order one of the Spring PropertySources is created if absent
      Parameters:
      environment - ConfigurableEnvironment
      Returns:
      non-null MapPropertySource
    • getDefaultPropertiesPropertySource

      public static org.springframework.core.env.MapPropertySource getDefaultPropertiesPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, boolean createIfAbsent)
      Get the "default" PropertySource that is the lowest order one of the Spring PropertySources is created if specified
      Parameters:
      environment - ConfigurableEnvironment
      createIfAbsent - true indicates the "default" PropertySource will be created if absent
      Returns:
      non-null MapPropertySource
    • containsPropertySource

      public static boolean containsPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, String propertySourceName)
      Contains the specified PropertySource or not
      Parameters:
      environment - ConfigurableEnvironment
      propertySourceName - the PropertySource name
      Returns:
      if contains, return true, otherwise false
    • containsBootstrapPropertySource

      public static boolean containsBootstrapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)
      Contains the Bootstrap PropertySource or not
      Parameters:
      environment - ConfigurableEnvironment
      Returns:
      if contains, return true, otherwise false