Package io.microsphere.spring.core.env
Class PropertySourcesUtils
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.spring.core.env.PropertySourcesUtils
-
public abstract class PropertySourcesUtils extends io.microsphere.util.BaseUtilsPropertySourcesUtilities- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
PropertySources
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBOOTSTRAP_PROPERTY_SOURCE_NAMEThePropertySource nameof Spring Cloud Bootstrap contextstatic java.lang.StringDEFAULT_PROPERTIES_PROPERTY_SOURCE_NAMEThePropertySource nameofSpring Boot default poperties
-
Constructor Summary
Constructors Constructor Description PropertySourcesUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String key, java.lang.Object value, java.lang.Object... others)static booleancontainsBootstrapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)Contains the BootstrapPropertySourceor notstatic booleancontainsPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName)Contains the specifiedPropertySourceor notstatic org.springframework.core.env.PropertySourcefindConfiguredPropertySource(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String propertyName)static org.springframework.core.env.PropertySourcefindConfiguredPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyName)static java.lang.StringfindConfiguredPropertySourceName(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String propertyName)static java.lang.StringfindConfiguredPropertySourceName(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyName)static java.util.Set<java.lang.String>findPropertyNames(org.springframework.core.env.ConfigurableEnvironment environment, java.util.function.Predicate<java.lang.String> propertyNameFilter)static java.util.Set<java.lang.String>findPropertyNamesByPrefix(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyNamePrefix)static java.util.Map<java.lang.String,java.lang.Object>getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment)Get theMapproperties from the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if absentstatic java.util.Map<java.lang.String,java.lang.Object>getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, boolean createIfAbsent)Get theMapproperties from the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if specified.static org.springframework.core.env.MapPropertySourcegetDefaultPropertiesPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)Get the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if absentstatic org.springframework.core.env.MapPropertySourcegetDefaultPropertiesPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, boolean createIfAbsent)Get the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if specifiedstatic org.springframework.core.env.MapPropertySourcegetMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName)static org.springframework.core.env.MapPropertySourcegetMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, boolean created)static java.util.Map<java.lang.String,java.lang.Object>getProperties(org.springframework.core.env.PropertySource propertySource)Get theMapas the properties from the specifiedPropertySourcestatic java.lang.String[]getPropertyNames(org.springframework.core.env.PropertySource propertySource)Get the property names as the array from the specifiedPropertySourceinstance.static <T extends org.springframework.core.env.PropertySource<?>>
TgetPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, java.lang.Class<T> propertySourceType)static <T extends org.springframework.core.env.PropertySource<?>>
TgetPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, java.lang.Class<T> propertySourceType, java.util.function.Supplier<T> propertySourceSupplierIfAbsent)static java.util.Map<java.lang.String,java.lang.Object>getSubProperties(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String prefix)Get SubPropertiesstatic java.util.Map<java.lang.String,java.lang.Object>getSubProperties(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String prefix)Get SubPropertiesstatic java.util.Map<java.lang.String,java.lang.Object>getSubProperties(org.springframework.core.env.PropertySources propertySources, java.lang.String prefix)Get prefixedPropertiesstatic java.util.Map<java.lang.String,java.lang.Object>getSubProperties(org.springframework.core.env.PropertySources propertySources, org.springframework.core.env.PropertyResolver propertyResolver, java.lang.String prefix)Get prefixedPropertiesstatic java.lang.StringnormalizePrefix(java.lang.String prefix)Normalize the prefix
-
-
-
Field Detail
-
DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME
public static final java.lang.String DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME
ThePropertySource nameofSpring 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 java.lang.String BOOTSTRAP_PROPERTY_SOURCE_NAME
ThePropertySource nameof Spring Cloud Bootstrap context- See Also:
org.springframework.cloud.bootstrap.BootstrapApplicationListener#BOOTSTRAP_PROPERTY_SOURCE_NAME, Constant Field Values
-
-
Method Detail
-
getPropertySource
public static <T extends org.springframework.core.env.PropertySource<?>> T getPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, java.lang.Class<T> propertySourceType)
-
getPropertySource
public static <T extends org.springframework.core.env.PropertySource<?>> T getPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, java.lang.Class<T> propertySourceType, java.util.function.Supplier<T> propertySourceSupplierIfAbsent)
-
getMapPropertySource
public static org.springframework.core.env.MapPropertySource getMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName)
-
getMapPropertySource
public static org.springframework.core.env.MapPropertySource getMapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName, boolean created)
-
findConfiguredPropertySource
public static org.springframework.core.env.PropertySource findConfiguredPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyName)
-
findConfiguredPropertySource
public static org.springframework.core.env.PropertySource findConfiguredPropertySource(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String propertyName)
-
findConfiguredPropertySourceName
public static java.lang.String findConfiguredPropertySourceName(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyName)
-
findConfiguredPropertySourceName
public static java.lang.String findConfiguredPropertySourceName(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String propertyName)
-
findPropertyNamesByPrefix
public static java.util.Set<java.lang.String> findPropertyNamesByPrefix(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertyNamePrefix)
-
findPropertyNames
public static java.util.Set<java.lang.String> findPropertyNames(org.springframework.core.env.ConfigurableEnvironment environment, java.util.function.Predicate<java.lang.String> propertyNameFilter)
-
getSubProperties
public static java.util.Map<java.lang.String,java.lang.Object> getSubProperties(java.lang.Iterable<org.springframework.core.env.PropertySource<?>> propertySources, java.lang.String prefix)Get SubProperties- Parameters:
propertySources-PropertySourceIterableprefix- the prefix of property name- Returns:
- Map
- See Also:
Properties
-
getSubProperties
public static java.util.Map<java.lang.String,java.lang.Object> getSubProperties(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String prefix)Get SubProperties- Parameters:
environment-ConfigurableEnvironmentprefix- the prefix of property name- Returns:
- Map
- See Also:
Properties
-
normalizePrefix
public static java.lang.String normalizePrefix(java.lang.String prefix)
Normalize the prefix- Parameters:
prefix- the prefix- Returns:
- the prefix
-
getSubProperties
public static java.util.Map<java.lang.String,java.lang.Object> getSubProperties(org.springframework.core.env.PropertySources propertySources, java.lang.String prefix)Get prefixedProperties- Parameters:
propertySources-PropertySourcesprefix- the prefix of property name- Returns:
- Map
- Since:
- 1.0.0
- See Also:
Properties
-
getSubProperties
public static java.util.Map<java.lang.String,java.lang.Object> getSubProperties(org.springframework.core.env.PropertySources propertySources, org.springframework.core.env.PropertyResolver propertyResolver, java.lang.String prefix)Get prefixedProperties- Parameters:
propertySources-PropertySourcespropertyResolver-PropertyResolverto resolve the placeholder if presentprefix- the prefix of property name- Returns:
- Map
- Since:
- 1.0.0
- See Also:
Properties
-
getPropertyNames
@Nonnull public static java.lang.String[] getPropertyNames(org.springframework.core.env.PropertySource propertySource)
Get the property names as the array from the specifiedPropertySourceinstance.- Parameters:
propertySource-PropertySourceinstance- Returns:
- non-null
- Since:
- 1.0.0
-
getProperties
@Nonnull public static java.util.Map<java.lang.String,java.lang.Object> getProperties(org.springframework.core.env.PropertySource propertySource)
Get theMapas the properties from the specifiedPropertySource- Parameters:
propertySource- the specifiedPropertySource- Returns:
- non-null read-only
Map
-
addDefaultProperties
public static void addDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String key, java.lang.Object value, java.lang.Object... others)
-
getDefaultProperties
public static java.util.Map<java.lang.String,java.lang.Object> getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment)
Get theMapproperties from the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if absent- Parameters:
environment-ConfigurableEnvironment- Returns:
- non-null mutable
Map - See Also:
DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME,getDefaultProperties(ConfigurableEnvironment, boolean)
-
getDefaultProperties
public static java.util.Map<java.lang.String,java.lang.Object> getDefaultProperties(org.springframework.core.env.ConfigurableEnvironment environment, boolean createIfAbsent)Get theMapproperties from the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if specified.- Parameters:
environment-ConfigurableEnvironmentcreateIfAbsent-trueindicates the "default"PropertySourcewill be created if absent- Returns:
- non-null mutable
Map - See Also:
DEFAULT_PROPERTIES_PROPERTY_SOURCE_NAME,getDefaultProperties(ConfigurableEnvironment, boolean)
-
getDefaultPropertiesPropertySource
public static org.springframework.core.env.MapPropertySource getDefaultPropertiesPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)
Get the "default"PropertySourcethat is the lowest order one of the SpringPropertySourcesis 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"PropertySourcethat is the lowest order one of the SpringPropertySourcesis created if specified- Parameters:
environment-ConfigurableEnvironmentcreateIfAbsent-trueindicates the "default"PropertySourcewill be created if absent- Returns:
- non-null
MapPropertySource
-
containsPropertySource
public static boolean containsPropertySource(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String propertySourceName)Contains the specifiedPropertySourceor not- Parameters:
environment-ConfigurableEnvironmentpropertySourceName-the PropertySource name- Returns:
- if contains, return
true, otherwisefalse
-
containsBootstrapPropertySource
public static boolean containsBootstrapPropertySource(org.springframework.core.env.ConfigurableEnvironment environment)
Contains the BootstrapPropertySourceor not- Parameters:
environment-ConfigurableEnvironment- Returns:
- if contains, return
true, otherwisefalse
-
-