Class RelaxedPropertySource
- All Implemented Interfaces:
PropertySource
PropertySource decorator that adds relaxed binding over a delegate source.
When a property lookup misses against the delegate, this source retries with a small set of
canonical name variants derived from the requested name, so a single logical key can be supplied in any of
the common environment conventions and still resolve. This is the mechanism that lets a Kubernetes-style
environment variable such as MY_SECTION_MY_KEY satisfy a lookup for MySection/myKey, or
MY_PROP satisfy my.prop / myProp.
Candidate order
The requested name is always tried verbatim first, so exact-match behavior is preserved unchanged (an already-canonical key resolves with no transformation, and a source that defines the literal name wins). Only on a miss are the relaxed variants tried, in this order:
- verbatim (the requested name, unchanged);
- upper underscore — every run of non-alphanumeric characters (and every lower→upper camel-case
boundary) becomes a single
_, then the whole thing is upper-cased. This is the dominant env-var form:my.prop/my-prop/myProp/MySection/myKey→MY_PROP/MY_SECTION_MY_KEY; - lower dotted — the same separator collapse but joined with
.and lower-cased (MY_PROP→my.prop), so a dotted-property lookup can be satisfied by an env-style key and vice-versa.
Because the boundary between "section" and "key" in a flat relaxed name (e.g. the underscores in
MY_SECTION_MY_KEY) is inherently ambiguous, this decorator deliberately works in the
lookup-key → candidate-name direction only (the well-defined direction): the caller asks for a known
logical key and the decorator generates the environment-convention spellings to probe. It never tries to reverse a
flat env name back into a section/key pair.
Usage
- Since:
- 10.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncandidates(String name) Generates the ordered, de-duplicated list of candidate names for a requested name (verbatim first).Returns a property in this property source.
-
Constructor Details
-
RelaxedPropertySource
Constructor.- Parameters:
delegate- The wrapped source that the generated candidate names are probed against. Must not benull .
-
-
Method Details
-
get
Description copied from interface:PropertySourceReturns a property in this property source.- Specified by:
getin interfacePropertySource- Parameters:
name- The property name.- Returns:
- The property lookup result:
PropertyLookupResult.missing()if this source does not define the key.PropertyLookupResult.present(Optional)withOptional.empty()if the key exists with a null value.PropertyLookupResult.present(Optional)with a value if the key exists with a non-null value.
-
candidates
Generates the ordered, de-duplicated list of candidate names for a requested name (verbatim first).The result is unmodifiable and memoized per name, with the same soft cap and pass-through rule as
CachingPropertySource(names beyondCachingPropertySource.MAX_ENTRIESare computed on every call).- Parameters:
name- The requested property name. Must not benull .- Returns:
- The candidate names to probe, in priority order. Unmodifiable.
- Throws:
NullPointerException- Ifname isnull .- Since:
- 10.0.0
-