Class PropertySource
Properties are checked in the following order:
- External properties (highest priority) - exact key match
- Environment variables (second priority) - with dot-to-underscore transformation
- Regular properties (lowest priority) - from system properties, files, and classpath
Property lookups remove entries from the maps. This allows detecting unused properties at the end of configuration loading.
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionPropertySource(Map<Object, Object> regularProperties) Creates a PropertySource with only regular properties (for testing).PropertySource(Map<Object, Object> externalProperties, Map<Object, Object> envVarProperties, Map<Object, Object> regularProperties) Creates a PropertySource with three separate property maps. -
Method Summary
Modifier and TypeMethodDescriptionReturns all keys from all three property sources.(package private) StringgetProperty(String key) Gets a property value by key, checking all three sources in priority order.(package private) StringgetProperty(String prefix, String propertyName) Gets a property value by prefix and property name.Returns all remaining keys from all three property sources.
-
Field Details
-
externalProperties
-
envVarProperties
-
regularProperties
-
-
Constructor Details
-
PropertySource
PropertySource(Map<Object, Object> externalProperties, Map<Object, Object> envVarProperties, Map<Object, Object> regularProperties) Creates a PropertySource with three separate property maps.- Parameters:
externalProperties- properties passed explicitly (e.g., from application code)envVarProperties- properties from environment variables (keys in env var format with underscores, lowercase)regularProperties- properties from system properties, files, and classpath (keys normalized to snake_case)
-
PropertySource
Creates a PropertySource with only regular properties (for testing).Creates empty maps for external and environment variable properties.
- Parameters:
regularProperties- properties from system properties, files, and classpath (keys normalized to snake_case)
-
-
Method Details
-
getProperty
Gets a property value by key, checking all three sources in priority order.For external and regular properties, performs exact key match. For environment variables, transforms dots to underscores before lookup (e.g., "io.prometheus.metrics.exemplars_enabled" becomes "io_prometheus_metrics_exemplars_enabled").
Removes the property from ALL source maps to prevent duplicate detection during validation.
- Parameters:
key- the property key to look up- Returns:
- the property value, or null if not found
-
getProperty
Gets a property value by prefix and property name.This is a convenience method that concatenates the prefix and property name with a dot and calls
getProperty(String).- Parameters:
prefix- the property prefix (e.g., "io.prometheus.metrics"), or empty string for no prefixpropertyName- the property name (e.g., "exemplars_enabled")- Returns:
- the property value, or null if not found
-
getAllKeys
Returns all keys from all three property sources.Keys are returned in the format they are stored in each source: external and regular properties typically use dot-separated keys, while environment variables are exposed in their underscore form (e.g., "io_prometheus_metrics_exemplars_enabled").
This is used for pattern matching to find metric-specific configurations.
- Returns:
- a set of all property keys
-
getRemainingKeys
-